For people who find continuation passing style (CPS) more reasonable than Promises, Futures, generators, etc.
that support passing callbacks to asynchronous APIs,
provides flow control keywords (i.e,
that are nearly useless once you need to await the future
At some point you realize you need to take a procedural approach and reimplement these keywords as functions.
In doing so, if you are familiar with assembly or machine code,
you may realize that all flow control operations can actually
be reduced to conditional JMP opcodes. Trendy variations like
do...while, etc. are unecessary
Taking the minimalist approach, you realize you can get a large degree of control with just a few functions that are a few lines of code each. No need for object instantiations, or multiple function calls in a builder pattern.
const ifAsync = ;
Flow Control Functions
- ifAsync : conditional branching without two callback references
- whileAsyncSerial: latched infinite loop
- forEachAsyncSerial : serial one-at-a-time invocation
- forEachAsyncParallel : parallel branch-join invocation
- forEachAsyncParallelBatch : parallel with limited maximum concurrent invocations
For when you have two functions: one that is asynchronous but is only executed sometimes, and one that is called afterward. Without this, you'd have to declare or reference the second function twice.
void ifAsync(test, true_cb[, ...args], done_cb);
Truthy value determines whether to invoke
The function invoked if the
testfunction above returns truthy. Accepts no targ Expected to be asynchronous. Accepts arguments provided in
...argsparameter described below. Void return value.
Optional. One or more arguments of any type, to be passed into
Function invoked after
true_cbcompletes. Invoked regardless of whether