@@ -100,18 +100,22 @@ export function async_derived(fn, location) {
100100 throw new Error ( 'TODO cannot create unowned async derived' ) ;
101101 }
102102
103+ let boundary = parent . b ;
104+
105+ while ( boundary !== null && ! boundary . has_pending_snippet ( ) ) {
106+ boundary = boundary . parent ;
107+ }
108+
109+ if ( boundary === null ) {
110+ throw new Error ( 'TODO cannot create async derived outside a boundary with a pending snippet' ) ;
111+ }
112+
103113 var promise = /** @type {Promise<V> } */ ( /** @type {unknown } */ ( undefined ) ) ;
104114 var signal = source ( /** @type {V } */ ( UNINITIALIZED ) ) ;
105115
106116 // only suspend in async deriveds created on initialisation
107117 var should_suspend = ! active_reaction ;
108118
109- var boundary = /** @type {Effect } */ parent . b ;
110-
111- while ( boundary !== null && ! boundary . has_pending_snippet ( ) ) {
112- boundary = boundary . parent ;
113- }
114-
115119 render_effect ( ( ) => {
116120 if ( DEV ) from_async_derived = active_effect ;
117121 promise = fn ( ) ;
@@ -125,10 +129,6 @@ export function async_derived(fn, location) {
125129 if ( fork !== null ) {
126130 fork . increment ( ) ;
127131 } else {
128- if ( boundary === null ) {
129- throw new Error ( 'TODO' ) ;
130- }
131-
132132 // if nearest pending boundary is not ready, attach to the boundary
133133 boundary . increment ( ) ;
134134 }
@@ -147,10 +147,6 @@ export function async_derived(fn, location) {
147147 if ( fork !== null ) {
148148 fork . decrement ( ) ;
149149 } else {
150- if ( boundary === null ) {
151- throw new Error ( 'TODO' ) ;
152- }
153-
154150 boundary . decrement ( ) ;
155151 }
156152 }
0 commit comments