Typescene Async Library
Library for strongly typed asynchronous programming, part of the Typescene toolkit.
Note: To learn more about Typescene, head over to the main Typescene repository.
Purpose of this module
This library provides a toolkit for asynchronous programming, primarily for the browser (or other browser-based front end, such as Electron). It has been created to support the development of the Typescene GUI toolkit.
This module exports generic classes and functions that implement common patterns for asynchronous programming, such as promises, signals, and observables.
The included functions and classes build on one another, in the following order:
deferfunction --- provides a basic queueing mechanism to schedule code asynchronously.
Signals --- defined using
defineSignal, which creates a class that derives from
Signal, of which instances can be emitted along with a single value. Like events, but different.
Promises --- the
Promiseclass provides a Promises/A+ compliant promise implementation, along with some additional convenience methods.
Observable values --- these are objects wrapped around a single value (in the
.valueproperty of an
ObservableValueobject), which can be subscribed to for capturing changes to this value. In addition, observables can be defined using a getter function, which may use other observable values in turn (making changes cascade asynchronously down a dependency tree when subscribed to; this can be employed to implement composite UIs efficiently).
Observable arrays --- arrays of observable values, hiding the
ObservableValueinstances in getters and setters for all array indices of an
Observable objects --- loosely defined objects for which some or all of the properties are made observable (using getters and setters) as properties of an
ObservableObject, which also defines a
PropertyChangesignal to listen for changes without having to subscribe to observable values directly.
- Injection --- this mechanism can be used to inject default (observable) values into a property on all instances of a class.
Refer to the samples for common usage patterns.