rewrite subtitle rendering engine

This commit is contained in:
2025-05-06 22:47:41 +02:00
parent 0d752a9038
commit 35bdb0d366
5 changed files with 315 additions and 134 deletions

View File

@@ -41,6 +41,33 @@ export function wait_for_dom_refresh(): Promise<void> {
});
}
/**
* Provides a locking abstraction around any ref-passed object to provide inner mutability that can
* automatically release on promise resolution. This provides "atomic transactions" on the inner
* type.
*
* This allows you to not await the transaction result, but offload the waiting to the next call
* to run. So other tasks can normally run when the transaction is executing. And if the inner
* type is needed again... the run call will wait for the (possibly) running transaction to
* finish first.
*/
export class AsyncRunner<T> {
private inner: T;
private lock: Promise<void>;
public constructor(inner: T) {
this.inner = inner;
this.lock = Promise.resolve();
}
public async run(transaction: (target: T) => Promise<void>): Promise<void> {
await this.lock;
this.lock = new Promise((resolver) => {
transaction(this.inner).then(() => { resolver() });
});
}
}
export namespace el {
function add_classes(target: HTMLElement, classes?: string[]): void {
if (classes === undefined) { return; }