24 lines
525 B
JavaScript
24 lines
525 B
JavaScript
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();
|
|
},
|
|
}
|
|
} |