constexpr = [ (opts) =>10, (opts) =>2, (opts) =>3 ]; constopts = { rank: (a, b) => { if (a < b) return -1; if (a > b) return1; return0; } } constresult = awaitrun(expr, opts); // Returns: 2
In terms of typing, it takes an generic arguments ArgsType and ResultType:
ArgsType: type of expression arguments. This might be void if no arguments are used.
ResultType: return type of expression functions
Thus the expressions parameter is an array of functions:
(args:ArgsType|undefined) =>ResultType|undefined // or (args:ArgsType|undefined) =>Promise<ResultType|undefined>
Example:
constexpressions = [ // Function takes a string arg (args:string) =>returntrue; // boolean is the necessary return type ]; construn<string,boolean>(expressions, opts, 'hello');
Runs a series of async expressions, returning the results. Use runSingle if it's only a single result you care about.
Example: Run three functions, returning the highest-ranked result.
Options can be passed for evaluation:
In terms of typing, it takes an generic arguments
ArgsType
andResultType
:ArgsType
: type of expression arguments. This might bevoid
if no arguments are used.ResultType
: return type of expression functionsThus the
expressions
parameter is an array of functions:Example: