mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 03:35:31 -05:00
wrap runPython in async (#1212)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user