Sub-project of Funfix, contains low level utilities and data types for building higher level concurrency tools.
Scheduling tasks for asynchronous execution:
Future | a lawful, fast, cancelable alternative to JavaScript's Promise |
Scheduler | the alternative to using setTimeout for asynchronous boundaries or delayed execution |
In support for futures and schedulers, ICancelable data types are introduced for dealing with cancellation concerns:
ICancelable and Cancelable | for expressing actions that can be triggered to cancel processes / dispose of resources |
IBoolCancelable and BoolCancelable | for cancelable references that can be queried for their isCanceled status |
IAssignCancelable and AssignCancelable | for cancelable references that can be assigned (behave like a box for) another reference |
MultiAssignCancelable | being a mutable cancelable whose underlying reference can be updated multiple times |
SingleAssignCancelable | for building forward references, much like MultiAssignCancelable except that it can be assigned only once, triggering an error on the second attempt |
SerialCancelable | being like a MultiAssignCancelable that cancels its previous underlying reference on updates |
And also types for expressing durations:
TimeUnit | inspired by Java's own enumeration, representing time | elated units of measurement |
Duration | inspired by Scala's own type, as a type safe representation for durations |
You can depend on the whole funfix
library, by adding it to
package.json
:
npm install --save funfix
In this case imports are like:
import { Future } from "funfix"
Or for finer grained dependency management, the project can depend
only on funfix-exec
:
npm install --save funfix-exec
In this case imports are like:
import { Future } from "funfix-exec"
Usage sample:
import { Future } from "funfix"
const f1 = Future.of(() => "hello")
const f2 = Future.of(() => "world")
const greeting = Future.map2(f1, f2, (a, b) => a + " " + b)
greeting.onComplete(r => {
r.fold(console.error, console.info)
})
The library has been compiled using UMD (Universal Module Definition), so it should work with CommonJS and AMD.
But it also provides a module
definition in package.json
, thus
providing compatibility with
ECMAScript 2015 modules, for usage when used with a modern JS engine,
or when bundling with a tool chain that understands ES2015 modules,
like Rollup or Webpack.
Time unit for representing days.
Time unit for representing hours.
Time unit for representing microseconds, where 1 microsecond is one thousandth of a millisecond.
Time unit for representing milliseconds, where 1 millisecond is one thousandth of a second.
Time unit for representing minutes.
Time unit for representing nanoseconds, where 1 nanosecond is one thousandth of a microsecond.
Time unit for representing seconds.
Type-class implementations, compatible with the static-land
specification.
Generated using TypeDoc
Type enumerating the type classes implemented by
Future
.