mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
升级queue为task
This commit is contained in:
1 parent
e7ce8c1f02
commit
5d7f57334f
14 files changed
+145
-130
No files matched your search
@@ -1,27 +0,0 @@
|
||||
const q = {};
|
||||
module.exports = {
|
||||
async connect() { }, // eslint-disable-line no-empty-function
|
||||
async assert(queue) {
|
||||
q[queue] = q[queue] || [];
|
||||
},
|
||||
async push(queue, data) {
|
||||
q[queue].push(data);
|
||||
},
|
||||
async get(queue, wait = true) {
|
||||
if (wait) {
|
||||
while (!q[queue].length) {
|
||||
await new Promise((resolve) => { // eslint-disable-line no-await-in-loop
|
||||
setTimeout(resolve, 100);
|
||||
});
|
||||
}
|
||||
const data = q[queue][0];
|
||||
q[queue].splice(0, 1);
|
||||
return data;
|
||||
}
|
||||
if (!q[queue].length) return null;
|
||||
|
||||
const data = q[queue][0];
|
||||
q[queue].splice(0, 1);
|
||||
return data;
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user