@@ -247,15 +247,14 @@ export function trigger_async_boundary(effect, trigger) {
247
247
/**
248
248
* @template T
249
249
* @param {Promise<T> } promise
250
- * @param {boolean } block
251
- * @returns {Promise<{ read: () => T }> }
250
+ * @returns {Promise<{ exit: () => T }> }
252
251
*/
253
- export function preserve_context ( promise , block = false ) {
252
+ export async function suspend ( promise ) {
254
253
var previous_effect = active_effect ;
255
254
var previous_reaction = active_reaction ;
256
255
var previous_component_context = component_context ;
257
256
258
- let boundary = block ? active_effect : null ;
257
+ let boundary = active_effect ;
259
258
while ( boundary !== null ) {
260
259
if ( ( boundary . f & BOUNDARY_EFFECT ) !== 0 ) {
261
260
break ;
@@ -264,25 +263,25 @@ export function preserve_context(promise, block = false) {
264
263
boundary = boundary . parent ;
265
264
}
266
265
267
- if ( block && boundary === null ) {
266
+ if ( boundary === null ) {
268
267
throw new Error ( 'cannot suspend outside a boundary' ) ;
269
268
}
270
269
271
270
// @ts -ignore
272
271
boundary ?. fn ( ASYNC_INCREMENT ) ;
273
272
274
- return promise . then ( ( value ) => {
275
- return {
276
- read ( ) {
277
- set_active_effect ( previous_effect ) ;
278
- set_active_reaction ( previous_reaction ) ;
279
- set_component_context ( previous_component_context ) ;
273
+ const value = await promise ;
280
274
281
- // @ts -ignore
282
- boundary ?. fn ( ASYNC_DECREMENT ) ;
275
+ return {
276
+ exit ( ) {
277
+ set_active_effect ( previous_effect ) ;
278
+ set_active_reaction ( previous_reaction ) ;
279
+ set_component_context ( previous_component_context ) ;
283
280
284
- return value ;
285
- }
286
- } ;
287
- } ) ;
281
+ // @ts -ignore
282
+ boundary ?. fn ( ASYNC_DECREMENT ) ;
283
+
284
+ return value ;
285
+ }
286
+ } ;
288
287
}
0 commit comments