mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
This includes the docker commands to get things compressed. And this is the start of the rpc, but needs lots of work, or very little, not sure yet anymore. I beleive that the things that are missing are the rpc, and the effects. So, lots of work, but is still good to have I suppose.
22 lines
687 B
TypeScript
22 lines
687 B
TypeScript
|
|
|
|
export class CallbackHolder {
|
|
constructor() {
|
|
|
|
}
|
|
private root = (Math.random() + 1).toString(36).substring(7);
|
|
private inc = 0
|
|
private callbacks = new Map<string, Function>()
|
|
private newId() {
|
|
return this.root + (this.inc++).toString(36)
|
|
}
|
|
addCallback(callback: Function) {
|
|
return this.callbacks.set(this.newId(), callback);
|
|
}
|
|
callCallback(index: string, args: any[]): Promise<unknown> {
|
|
const callback = this.callbacks.get(index)
|
|
if (!callback) throw new Error(`Callback ${index} does not exist`)
|
|
this.callbacks.delete(index)
|
|
return Promise.resolve().then(() => callback(...args))
|
|
}
|
|
} |