mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: use p-queue
This commit is contained in:
1 parent
636446c43a
commit
1394af0591
3 files changed
+7
-44
No files matched your search
@@ -15,10 +15,10 @@
|
||||
~ */
|
||||
import './utils';
|
||||
|
||||
import PQueue from 'p-queue';
|
||||
import { getConfig } from './config';
|
||||
import HydroHost from './hosts/hydro';
|
||||
import log from './log';
|
||||
import { Queue } from './utils';
|
||||
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
@@ -51,18 +51,11 @@ process.on('unhandledRejection', (reason, p) => {
|
||||
console.log('Unhandled Rejection at: Promise ', p);
|
||||
});
|
||||
|
||||
async function worker(queue: Queue<any>) {
|
||||
while ('Orz Soha') {
|
||||
const [task] = await queue.get();
|
||||
task.handle();
|
||||
}
|
||||
}
|
||||
|
||||
async function daemon() {
|
||||
const _hosts = getConfig('hosts');
|
||||
const hosts = {};
|
||||
const queue = new Queue<any>();
|
||||
worker(queue).catch((e) => log.error(e));
|
||||
const queue = new PQueue({ concurrency: Infinity });
|
||||
queue.on('error', (e) => log.error(e));
|
||||
for (const i in _hosts) {
|
||||
_hosts[i].host = _hosts[i].host || i;
|
||||
hosts[i] = new HydroHost(_hosts[i]);
|
||||
|
||||
Reference in new issue
Block a user