mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
Merge pull request #1010 from bbassie/feature/plugin-browser
Plugin management through web interface
This commit is contained in:
1 parent
e36a76acc5
commit
ffe82f81d8
48 files changed
+4275
-536
No files matched your search
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Run a task now and again intervalMs after each run finishes, so runs never overlap.
|
||||
* setInterval can't be used as an async task may take longer than the interval.
|
||||
* The task handles its own errors.
|
||||
*
|
||||
* @returns Function that stops polling, a run in progress still finishes
|
||||
*/
|
||||
export function poll(task: () => Promise<void>, intervalMs: number) {
|
||||
let stopped = false;
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
async function run() {
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
await task();
|
||||
// Stopping while the task ran must not schedule another run
|
||||
if (!stopped) {
|
||||
timeout = setTimeout(run, intervalMs);
|
||||
}
|
||||
}
|
||||
run();
|
||||
return () => {
|
||||
stopped = true;
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user