mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53: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,25 @@
|
||||
/** Runs one task at a time, refusing tasks started while another is running */
|
||||
export class ExclusiveRunner<State> {
|
||||
current?: State;
|
||||
onChange: (state?: State) => void;
|
||||
|
||||
constructor(onChange: (state?: State) => void) {
|
||||
this.onChange = onChange;
|
||||
}
|
||||
|
||||
/** Run the task unless another is running, returns false if it was refused */
|
||||
async run(state: State, task: () => Promise<void>) {
|
||||
if (this.current !== undefined) {
|
||||
return false;
|
||||
}
|
||||
this.current = state;
|
||||
this.onChange(state);
|
||||
try {
|
||||
await task();
|
||||
} finally {
|
||||
this.current = undefined;
|
||||
this.onChange(undefined);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user