Skip to content

Commit

Permalink
remove extra await from after!
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Dec 27, 2022
1 parent 682005a commit 8cebd7e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/jsutils/after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ export async function after<T, R = T, U = T>(
onError?: (error: any) => U,
): Promise<R | U> {
try {
const result =
onFulfilled === undefined
? ((await promise) as R)
: onFulfilled(await promise);
if (onFulfilled === undefined) {
return (await promise) as R;
}

const result = onFulfilled(await promise);

if (isPromise(result)) {
return await result;
}

return result;
} catch (error) {
if (onError === undefined) {
Expand Down

0 comments on commit 8cebd7e

Please sign in to comment.