UNPKG

1.28 kBPlain TextView Raw
1import Promise = require('bluebird');
2export = RunContext;
3
4
5/**
6 * This class is used to pass all required contextual information to the runInFiber()
7 * function as a single argument. runInFiber() can only accept a single argument because
8 * it is invoked via Fiber#run(), which can only pass through a single argument.
9 */
10class RunContext {
11
12 /** Construct a new RunContext instance. */
13 constructor(wrapped: Function, thisArg, argsAsArray: any[], done?: () => void) {
14 this.wrapped = wrapped;
15 this.thisArg = thisArg;
16 this.argsAsArray = argsAsArray;
17 this.done = done;
18 }
19
20 /** The function to be executed in a fiber. */
21 wrapped: Function;
22
23 /** 'this' context to be applied to the wrapped function. */
24 thisArg: any;
25
26 /** The arguments to pass to the wrapped function. */
27 argsAsArray: any[];
28
29 /** Optional callback to unconditionally call after the wrapped function has exited. */
30 done: () => void;
31
32 /** Optional promise resolver for notifying the wrapped function's return/throw value. */
33 resolver: Promise.Resolver<any> = null;
34
35 /** Optional callback for notifying the wrapped function's return/throw value. */
36 callback: (err, val?) => void = null;
37}