JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 53
  • Score
    100M100P100Q49235F
  • License MIT

Promises running in separated threads

Package Exports

  • thread-promises

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (thread-promises) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ThreadPromises

Promises running in separated threads

NPM

It is an early version.

Now it support only then and catch methods. But it works.

It creates a thread for every task so it not blocking main thread and it could run in parallel

screenshot

Installing

<script src="/lib/thread-promises.min.js"></script>

Or

<script src="https://cdn.jsdelivr.net/npm/thread-promises/lib/thread-promises.min.js"></script>

Or

npm i --save thread-promises
import TPromise from "thread-promises"

Examples

All examples

Expample of making blocking job on main thread and on TPromise's thread

Simple resolve on timeout

Simple reject on timeout

Usage

new TPromise((resolve, reject) => {
    console.log("Look ma, I am multithread JavaScript!")
})

For additional properties put them after executor function (like in setTimeout):

new TPromise((resolve, reject, some, additional, properties) => {
    console.log("I have no access to my old lexical environment, but I can use props")
    console.log(some, additional, properties)
}, some, additional, properties)