Options
All
  • Public
  • Public/Protected
  • All
Menu

funfix-exec

Sub-project of Funfix, contains low level utilities and data types for building higher level concurrency tools.

Contents

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

Usage

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)
})

Modules: UMD and ES 2015

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.

Index

Type aliases

FutureTypes

FutureTypes: Monad<"funfix/future">

Type enumerating the type classes implemented by Future.

Variables

Const DAYS

DAYS: TimeUnit = new Days()

Time unit for representing days.

Const HOURS

HOURS: TimeUnit = new Hours()

Time unit for representing hours.

Const MICROSECONDS

MICROSECONDS: TimeUnit = new Microseconds()

Time unit for representing microseconds, where 1 microsecond is one thousandth of a millisecond.

Const MILLISECONDS

MILLISECONDS: TimeUnit = new Milliseconds()

Time unit for representing milliseconds, where 1 millisecond is one thousandth of a second.

Const MINUTES

MINUTES: TimeUnit = new Minutes()

Time unit for representing minutes.

Const NANOSECONDS

NANOSECONDS: TimeUnit = new Nanoseconds()

Time unit for representing nanoseconds, where 1 nanosecond is one thousandth of a microsecond.

Const SECONDS

SECONDS: TimeUnit = new Seconds()

Time unit for representing seconds.

Object literals

Const FutureModule

FutureModule: object

Type-class implementations, compatible with the static-land specification.

of

of: pure = Future.pure

ap

chain

chainRec

  • chainRec<A, B>(f: function, a: A): Future<B>
  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • <C>(next: function, done: function, a: A): Future<C>
        • Type parameters

          • C

          Parameters

          • next: function
              • (a: A): C
              • Parameters

                • a: A

                Returns C

          • done: function
              • (b: B): C
              • Parameters

                • b: B

                Returns C

          • a: A

          Returns Future<C>

    • a: A

    Returns Future<B>

map

  • Type parameters

    • A

    • B

    Parameters

    • f: function
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • fa: Future<A>

    Returns Future<B>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc