UNPKG

1.19 kBPlain TextView Raw
1import types = require('../types');
2import Config = require('./config');
3import makeAsyncFunc = require('./makeAsyncFunc');
4export = async;
5
6
7/**
8 * Creates a suspendable function. Suspendable functions may use the await() function
9 * internally to suspend execution at arbitrary points, pending the results of
10 * internal asynchronous operations.
11 * @param {Function} fn - Contains the body of the suspendable function. Calls to await()
12 * may appear inside this function.
13 * @returns {Function} A function of the form `(...args) --> Promise`. Any arguments
14 * passed to this function are passed through to fn. The returned
15 * promise is resolved when fn returns, or rejected if fn throws.
16 */
17var async: types.Async = <any> makeAsyncFunc(new Config());
18async.cps = <any> async.mod('returns: none, callback: true, iterable: false');
19async.thunk = <any> async.mod('returns: thunk, callback: false, iterable: false');
20async.result = <any> async.mod('returns: result, callback: false, iterable: false');
21async.iterable = <any> async.mod('returns: promise, callback: false, iterable: true');