Skip to content

Commit

Permalink
Merge pull request #386 from Telegram-Mini-Apps/376-bug-unhandled-exc…
Browse files Browse the repository at this point in the history
…eption-while-closing-the-qr-scanner-screen

fix(sdk): remove Promise.withResolvers
  • Loading branch information
heyqbnk authored Jul 6, 2024
2 parents 1963c98 + 7e2bd76 commit f8b6518
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/sdk/src/bridge/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export type RequestOptions<M extends MiniAppsMethodName, E, C> = {
params: MiniAppsMethodParams<M>
}>;

type AnyRequestResult =
| MiniAppsEventPayload<MiniAppsEventName>
| RequestEventsPayloads<MiniAppsEventName[]>;

/**
* Calls specified Mini Apps method and captures specified event.
* @param options - method options.
Expand All @@ -81,14 +85,9 @@ export async function request<M extends MiniAppsMethodName>(
options:
| RequestOptions<M, MiniAppsEventName, RequestCaptureEventFn<MiniAppsEventName>>
| RequestOptions<M, MiniAppsEventName[], RequestCaptureEventsFn<MiniAppsEventName[]>>,
): Promise<
| MiniAppsEventPayload<MiniAppsEventName>
| RequestEventsPayloads<MiniAppsEventName[]>
> {
const { resolve, promise } = Promise.withResolvers<
| MiniAppsEventPayload<MiniAppsEventName>
| RequestEventsPayloads<MiniAppsEventName[]>
>();
): Promise<AnyRequestResult> {
let resolve: (payload: AnyRequestResult) => void;
const promise = new Promise<AnyRequestResult>(res => resolve = res);

const { event, capture, timeout } = options;
const [, cleanup] = createCleanup(
Expand Down

0 comments on commit f8b6518

Please sign in to comment.