initial commit
This commit is contained in:
24
src/lib/queue.js
Normal file
24
src/lib/queue.js
Normal file
@ -0,0 +1,24 @@
|
||||
export default function() {
|
||||
return {
|
||||
items: [],
|
||||
|
||||
resolvers: []
|
||||
|
||||
put(item) {
|
||||
this.items.push(item);
|
||||
if (resolvers.length > 0) {
|
||||
resolvers.shift().resolve();
|
||||
}
|
||||
},
|
||||
|
||||
async get() {
|
||||
if (this.items.length === 0) {
|
||||
await new Promise((resolve, reject) => {
|
||||
this.resolvers.push(resolve);
|
||||
})
|
||||
}
|
||||
|
||||
return this.items.shift();
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user