Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition with registering webview postMessage calls over RPC #1406

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/platform-bible-utils/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-utils/dist/index.cjs.map

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions lib/platform-bible-utils/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,58 @@ export declare class PlatformEventEmitter<T> implements Dispose {
*/
protected disposeFn(): Promise<boolean>;
}
/**
* Class that allows you to chain promises for a given key. This is useful when:
*
* 1. You need to run promises from synchronous code and don't need to look at the results.
* 2. The promises to run, or at least precisely when to run them, are not known in advance.
* 3. The promises need to be run sequentially, waiting for the previous one to finish.
*
* An example of when this can be helpful is inside of React components. Component code is mostly
* synchronous, but you may need to run some asynchronous code. You can't use `await` inside of
* React component code in many situations, so you can use this class to chain promises together.
*
* When promises are added to the map with a key, they will run in the order they were added to the
* map for that key. If a promise rejects, a warning will be logged and the chain will continue. If
* a promise is added while another promise in the map for that key is running, the new promise will
* be chained to the existing one.
*/
export declare class PromiseChainingMap<TKey = string> {
private readonly map;
private readonly logger;
/**
* Creates a new PromiseChainingMap
*
* @param logger Object with a `warn` method that will be called when a promise rejects
*/
constructor(logger?: {
warn: (message: string) => void;
});
/**
* Adds a promise to the map for a given key. If a promise is already running for the key, the new
* promise will be chained to the existing one. Once all promises for a key have settled, the map
* will be cleared for that key.
*
* @param key Unique key to identify a distinct promise chain
* @param promiseFunction Function that returns a promise to add to the chain
*/
addPromise(key: TKey, promiseFunction: () => Promise<unknown>): void;
/**
* Gets the current promise chain for the given key. This is mostly useful for testing. Normally
* you should just call {@link addPromise} and let the map handle the rest.
*
* @param key Unique key to identify a distinct promise chain
* @returns The current promise chain for the key
*/
get(key: TKey): Promise<unknown> | undefined;
/**
* Configures a promise chain to be removed from the map for the given key after all the promises
* have settled
*
* @param key Unique key to identify a distinct promise chain
*/
private cleanupPromiseChain;
}
/** Simple collection for UnsubscriberAsync objects that also provides an easy way to run them. */
export declare class UnsubscriberAsyncList {
private name;
Expand Down
Loading
Loading