File tree Expand file tree Collapse file tree 3 files changed +16
-11
lines changed
Expand file tree Collapse file tree 3 files changed +16
-11
lines changed Original file line number Diff line number Diff line change 99 "preact-render-to-string" :
" https://esm.sh/*[email protected] " ,
1010 "@preact/signals" :
" https://esm.sh/*@preact/[email protected] " ,
1111 "@preact/signals-core" :
" https://esm.sh/@preact/[email protected] " ,
12- "std/" : " https://deno.land/std@0.182 .0/"
12+ "std/" : " https://deno.land/std@0.211 .0/"
1313 }
1414}
Original file line number Diff line number Diff line change 1- import { Deferred , deferred } from "std/async/deferred.ts" ;
2-
31export const createPool = < T > ( resources : T [ ] ) => {
42 const taken = new Set < number > ( ) ;
53 const free = new Set < number > ( resources . map ( ( _ , i ) => i ) ) ;
64
7- const waiting : Deferred < T > [ ] = [ ] ;
5+ const waiting : Array < {
6+ promise : Promise < T > ;
7+ resolve : ( value : T | PromiseLike < T > ) => void ;
8+ // deno-lint-ignore no-explicit-any
9+ reject : ( reason ?: any ) => void ;
10+ } > = [ ] ;
811
912 return {
1013 acquire : ( ) => {
1114 if ( free . size === 0 ) {
12- const p = deferred < T > ( ) ;
15+ const p = Promise . withResolvers < T > ( ) ;
1316 waiting . push ( p ) ;
1417
1518 return p ;
Original file line number Diff line number Diff line change 11// deno-lint-ignore-file no-explicit-any
2- import { Deferred , deferred } from "std/async/deferred.ts" ;
3-
42/**
53 * Deco labs: 🐁🐁🐁
64 *
@@ -52,9 +50,13 @@ export const createWorker = (
5250 url : URL ,
5351 options ?: WorkerOptions | undefined ,
5452) : Promise < any > => {
55- const setup = deferred ( ) ;
53+ const setup = Promise . withResolvers ( ) ;
5654 const worker = new Worker ( new URL ( import . meta. url ) , options ) ;
57- const invokes = new Map < string , Deferred < unknown > > ( [ ] ) ;
55+ const invokes = new Map < string , {
56+ promise : Promise < any > ;
57+ resolve : ( value : any | PromiseLike < any > ) => void ;
58+ reject : ( reason ?: any ) => void ;
59+ } > ( [ ] ) ;
5860
5961 worker . postMessage ( { type : "setup" , payload : url . href } ) ;
6062
@@ -65,7 +67,7 @@ export const createWorker = (
6567 case "setup:fulfill" : {
6668 const mod = payload . reduce ( ( acc , curr ) => {
6769 acc [ curr ] = ( ...args : any [ ] ) => {
68- const run = deferred < void > ( ) ;
70+ const run = Promise . withResolvers < any > ( ) ;
6971 const id = crypto . randomUUID ( ) ;
7072
7173 invokes . set ( id , run ) ;
@@ -116,7 +118,7 @@ export const createWorker = (
116118 }
117119 } ) ;
118120
119- return setup ;
121+ return setup . promise ;
120122} ;
121123
122124if ( IS_WORKER ) {
You can’t perform that action at this time.
0 commit comments