wrap runPython in async (#1212)

This commit is contained in:
Madhur Tandon
2023-02-21 20:35:19 +00:00
committed by GitHub
parent 11c79a5344
commit e2c2459290
14 changed files with 158 additions and 42 deletions

View File

@@ -112,3 +112,26 @@ export function createSingularWarning(msg: string, sentinelText: string | null =
_createAlertBanner(msg, 'warning');
}
}
/**
* @returns A new asynchronous lock
* @private
*/
export function createLock() {
// This is a promise that is resolved when the lock is open, not resolved when lock is held.
let _lock = Promise.resolve();
/**
* Acquire the async lock
* @returns A zero argument function that releases the lock.
* @private
*/
async function acquireLock() {
const old_lock = _lock;
let releaseLock: () => void;
_lock = new Promise((resolve) => (releaseLock = resolve));
await old_lock;
return releaseLock;
}
return acquireLock;
}