Skip to content

Commit

Permalink
fix: no error should occur when the timeout is set to 0 (gronxb#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
gronxb authored Apr 28, 2024
1 parent 20f885a commit 6d48c92
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions packages/web/src/linkBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,32 @@ const createNativeMethod =
(...args: unknown[]) => {
const eventId = createRandomId();

return Promise.race([
createResolver({
emitter,
methodName,
eventId,
evaluate: () => {
window.ReactNativeWebView?.postMessage(
JSON.stringify({
type: "bridge",
body: {
method: methodName,
eventId,
args,
},
}),
);
},
onFallback: () => {
onFallback?.(methodName, args);
},
failHandler: throwOnError && new NativeMethodError(methodName),
}),
timeout(timeoutMs, throwOnError),
]);
return Promise.race(
[
createResolver({
emitter,
methodName,
eventId,
evaluate: () => {
window.ReactNativeWebView?.postMessage(
JSON.stringify({
type: "bridge",
body: {
method: methodName,
eventId,
args,
},
}),
);
},
onFallback: () => {
onFallback?.(methodName, args);
},
failHandler: throwOnError && new NativeMethodError(methodName),
}),
timeoutMs > 0 && timeout(timeoutMs, throwOnError),
].filter(Boolean),
);
};

export const linkBridge = <
Expand Down

0 comments on commit 6d48c92

Please sign in to comment.