create-async-flag
Simple promise utility for separate, but dependent control flow. See example here.
API
createAsyncFlag()
Creates a flag that can be set
, unset
, and wait
upon.
import createAsyncFlag from 'create-async-flag';
const flag = createAsyncFlag();
[flag].wait()
Creates a promise that will only resolve once set
, or resolve immediatly if already set
.
const flag = createAsyncFlag();
async function run() {
await flag.wait();
}
[flag].set()
Marks the flag to be immediatly resolved, and to resolve any currently waiting promises.
const flag = createAsyncFlag();
function log() {
flag.wait().then(() => console.log('one'));
flag.set();
flag.wait().then(() => console.log('two'));
}
log();
[flag].unset()
Marks a flag to wait until set is called again.
const flag = createAsyncFlag();
async function start() {
flag.unset();
await flag.wait();
return;
}
[flag].isSet()
Returns the current state of the flag.
const flag = createAsyncFlag();
flag.isSet();
flag.set();
flag.isSet();