File tree 1 file changed +14
-10
lines changed
packages/runtime-core/src
1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change
1
+ import { isPromise } from '../../shared/src'
1
2
import {
2
3
getCurrentInstance ,
3
4
SetupContext ,
@@ -232,19 +233,22 @@ export function mergeDefaults(
232
233
* Runtime helper for storing and resuming current instance context in
233
234
* async setup().
234
235
*/
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 > {
238
237
const ctx = getCurrentInstance ( )
239
238
setCurrentInstance ( null ) // unset after storing instance
240
239
if ( __DEV__ && ! ctx ) {
241
240
warn ( `withAsyncContext() called when there is no active context instance.` )
242
241
}
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 )
250
254
}
You can’t perform that action at this time.
0 commit comments