gm api通信
Some checks failed
test / Run tests (push) Failing after 9s
build / Build (push) Failing after 16s
Some checks failed
test / Run tests (push) Failing after 9s
build / Build (push) Failing after 16s
This commit is contained in:
25
src/pkg/utils/queue.ts
Normal file
25
src/pkg/utils/queue.ts
Normal file
@ -0,0 +1,25 @@
|
||||
// 一个简单的队列,可以使用pop阻塞等待消息
|
||||
export default class Queue<T> {
|
||||
list: T[] = [];
|
||||
|
||||
resolve?: (data: T) => void;
|
||||
|
||||
push(data: T) {
|
||||
if (this.resolve) {
|
||||
this.resolve(data);
|
||||
this.resolve = undefined;
|
||||
} else {
|
||||
this.list.push(data);
|
||||
}
|
||||
}
|
||||
|
||||
pop(): Promise<T | undefined> {
|
||||
return new Promise((resolve) => {
|
||||
if (this.list.length > 0) {
|
||||
resolve(this.list.shift());
|
||||
} else {
|
||||
this.resolve = resolve;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -277,7 +277,7 @@ export function prepareScriptByCode(
|
||||
let old: Script | undefined;
|
||||
let oldCode: string | undefined;
|
||||
if (uuid) {
|
||||
old = await dao.findByUUID(uuid);
|
||||
old = await dao.get(uuid);
|
||||
if (!old && override) {
|
||||
old = await dao.findByNameAndNamespace(script.name, script.namespace);
|
||||
}
|
||||
|
Reference in New Issue
Block a user