Skip to content

Commit 8936707

Browse files
committed
Use std 211
Signed-off-by: Marcos Candeia <[email protected]>
1 parent f88d70e commit 8936707

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

import_map.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
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
}

utils/pool.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import { Deferred, deferred } from "std/async/deferred.ts";
2-
31
export 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;

utils/worker.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
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

122124
if (IS_WORKER) {

0 commit comments

Comments
 (0)