async-counter
An asynchronous counter with a sync interface
Install
npm i --save async-counter
Usage
; const counter = ; // Inside an async blockconst logWhenFinished = async console; // Somewhere else, async code;;// `counter` resolves the second time `counter.count` is called ;// Output after a second:// Finished counting to 2!
API
const counter = ; for let i = 0; i < 3; i++ ;// Output:// Wed Feb 27 2019 04:40:05 GMT-0500 (Eastern Standard Time): 1 of 3 times// Wed Feb 27 2019 04:40:06 GMT-0500 (Eastern Standard Time): 2 of 3 times// Wed Feb 27 2019 04:40:07 GMT-0500 (Eastern Standard Time): 3 of 3 times// Finished counting to 3!