jseventqueue
A JavaScript (ES6) library for serializing event processing. It is intended to be used by multiple producers and a single consumer. Event processing is using ayns/await mechanism, which helps to process events one-at-a-time.
Reading from queue using for await
loop:
const EventQueue = ;let queue = ;;let results = ;for { results;}// results contain [0, 1, 2, 3]
If for some reason one can't use for await
loop then a similar loop can be implemented using while
:
const EventQueue = ;let queue = ;;let results = ;let data;// while loop checks whether queue was shutdown by comparing returned value// to a special data member of the queue objectwhile data = await queue !== queueend results;// results contain [0, 1, 2, 3]
Ad-hoc reading and writing to the queue:
const EventQueue = ;let queue = ;;// receive will wait until a message is receivedlet msg1 = await queue;let msg2 = await queue;
Installation
Using npm:
$ npm i --save jseventqueue