|  |  | @ -34,14 +34,15 @@ import { | 
			
		
	
		
		
			
				
					
					|  |  |  | 	skip_nodes |  |  |  | 	skip_nodes | 
			
		
	
		
		
			
				
					
					|  |  |  | } from '../dom/hydration.js'; |  |  |  | } from '../dom/hydration.js'; | 
			
		
	
		
		
			
				
					
					|  |  |  | import { create_text } from '../dom/operations.js'; |  |  |  | import { create_text } from '../dom/operations.js'; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import { noop } from '../../shared/utils.js'; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | /** |  |  |  | /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @param {Array<Promise<any>>} dependencies |  |  |  |  * @param {Promise<void> | undefined} blocker | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  * @param {Array<() => any>} sync |  |  |  |  * @param {Array<() => any>} sync | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @param {Array<() => Promise<any>>} async |  |  |  |  * @param {Array<() => Promise<any>>} async | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @param {(values: Value[]) => any} fn |  |  |  |  * @param {(values: Value[]) => any} fn | 
			
		
	
		
		
			
				
					
					|  |  |  |  */ |  |  |  |  */ | 
			
		
	
		
		
			
				
					
					|  |  |  | export function flatten(dependencies, sync, async, fn) { |  |  |  | export function flatten(blocker, sync, async, fn) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	const d = is_runes() ? derived : derived_safe_equal; |  |  |  | 	const d = is_runes() ? derived : derived_safe_equal; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	if (async.length === 0) { |  |  |  | 	if (async.length === 0) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -56,12 +57,10 @@ export function flatten(dependencies, sync, async, fn) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	var was_hydrating = hydrating; |  |  |  | 	var was_hydrating = hydrating; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	Promise.all(dependencies).then((values) => { |  |  |  | 	Promise.resolve(blocker).then((values) => { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		restore(); |  |  |  | 		restore(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		const result = Promise.all( |  |  |  | 		const result = Promise.all(async.map((expression) => async_derived(expression))) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			async.map((expression) => async_derived(() => expression(...values))) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 		) |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			.then((result) => { |  |  |  | 			.then((result) => { | 
			
		
	
		
		
			
				
					
					|  |  |  | 				restore(); |  |  |  | 				restore(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -271,10 +270,25 @@ export async function async_body(anchor, fn) { | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | /** |  |  |  | /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @param {Array<Promise<any>>} deps |  |  |  |  * @param {Array<() => void | Promise<void>>} thunks | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |  * @param {(...deps: any) => any} fn |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  */ |  |  |  |  */ | 
			
		
	
		
		
			
				
					
					|  |  |  | export function run(deps, fn) { |  |  |  | export function run(thunks) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	// TODO save/restore context
 |  |  |  | 	const restore = capture(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 	return Promise.all(deps).then(fn); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	let promise = Promise.resolve(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	return thunks.map((fn) => { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		promise = promise | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			.then(() => { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				try { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 					restore(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 					return fn(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				} finally { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 					unset_context(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			.then(noop); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		return promise; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	}); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |