将题目纳入rating计算系统

This commit is contained in:
undefined committed 2020-07-17 16:59:39 +08:00
1 parent bf29661eaa
commit 17b38cbf4e
19 files changed
+290 -271

No files matched your search

+36 -1
View File
@@ -57,6 +57,41 @@ export async function consume(query: any, cb: Function) {
}, 100);
}
export class Consumer {
consuming: boolean;
running?: Promise<any>;
interval: NodeJS.Timeout;
filter: any;
func: Function;
constructor(filter: any, func: Function) {
this.consuming = true;
this.filter = filter;
this.func = func;
this.interval = setInterval(this.consume.bind(this), 100);
}
async consume() {
if (this.running || !this.consuming) return;
const res = await getFirst(this.filter);
if (res) {
this.running = this.func(res);
if (this.running instanceof Promise) await this.running;
this.running = null;
}
}
async destory() {
this.consuming = false;
clearInterval(this.interval);
if (this.running) await this.running;
}
}
global.Hydro.model.task = {
add, get, del, count, getFirst, consume,
Consumer, add, get, del, count, getFirst, consume,
};