promise-critical-section
Allows only one asynchronous operation to run every time.
Although JavaScript is single-threaded, there are times you may want to limit number of asynchronous operation to enter a block simultaneously. For example,
- Pooling a single resource
- Running a series of asynchronous steps one-by-one
How to use
In the code below, Step 1A
and Step 1B
will be run serially regardless of race condition from Step 2
.
; const section = ; Promise
You can also write it with ES7 async/await. The following example maybe a bit exaggerated.
return Promiseall async { await section; console; console; await section; } async { await section; console; await section; };
Contributions
Like us? Please star us or give us suggestions.
Please file an issue to us with minimal repro.