Skip to content

Commit 438754a

Browse files
committed
fix(build): avoid using async/await syntax
1 parent a44d528 commit 438754a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/runtime-core/src/apiSetupHelpers.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isPromise } from '../../shared/src'
12
import {
23
getCurrentInstance,
34
SetupContext,
@@ -232,19 +233,22 @@ export function mergeDefaults(
232233
* Runtime helper for storing and resuming current instance context in
233234
* async setup().
234235
*/
235-
export async function withAsyncContext<T>(
236-
awaitable: T | Promise<T>
237-
): Promise<T> {
236+
export function withAsyncContext<T>(awaitable: T | Promise<T>): Promise<T> {
238237
const ctx = getCurrentInstance()
239238
setCurrentInstance(null) // unset after storing instance
240239
if (__DEV__ && !ctx) {
241240
warn(`withAsyncContext() called when there is no active context instance.`)
242241
}
243-
let res: T
244-
try {
245-
res = await awaitable
246-
} finally {
247-
setCurrentInstance(ctx)
248-
}
249-
return res
242+
return isPromise<T>(awaitable)
243+
? awaitable.then(
244+
res => {
245+
setCurrentInstance(ctx)
246+
return res
247+
},
248+
err => {
249+
setCurrentInstance(ctx)
250+
throw err
251+
}
252+
)
253+
: (awaitable as any)
250254
}

0 commit comments

Comments
 (0)