rework routing

This commit is contained in:
Joseph Montanaro 2022-11-21 21:23:50 -08:00
parent 636cdf1b8f
commit e37c07adb4

View File

@ -1,13 +1,19 @@
/* Simple asynchronous queue.
To make `get` blocking, we create a new promise and store its `resolve` function in `resolvers`.
The next time an item is added to the queue, it will be resolved.
*/
export default function() {
return {
items: [],
resolvers: []
resolvers: [],
put(item) {
this.items.push(item);
if (resolvers.length > 0) {
resolvers.shift().resolve();
if (this.resolvers.length > 0) {
let resolver = this.resolvers.shift();
resolver();
}
},