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: Playground not starting due to a race condition #1084

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
14 changes: 7 additions & 7 deletions packages/php-wasm/web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ export function consumeAPI<APIType>(
get: (target, prop) => {
if (prop === 'isConnected') {
return async () => {
/*
* If exposeAPI() is called after this function,
* the isConnected() call will hang forever. Let's
* retry it a few times.
*/
for (let i = 0; i < 10; i++) {
// Keep retrying until the remote API confirms it's connected.
while (true) {
try {
await runWithTimeout(api.isConnected(), 200);
break;
} catch (e) {
// Timeout exceeded, try again
// Timeout exceeded, try again. We can't just use a single
// `runWithTimeout` call because it won't reach the remote API
// if it's not connected yet. Instead, we need to keep retrying
// until the remote API is connected and registers a handler
// for the `isConnected` method.
}
}
};
Expand Down
Loading