@effectionx/worker 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +16 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.js +22 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.js +186 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +35 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.js +59 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.js +22 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.js +52 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +25 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +32 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.js +167 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +42 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.js +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.js +20 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +80 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.js +116 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +140 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.js +276 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +99 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.js +182 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts +29 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.js +70 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +159 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.js +207 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts +25 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.js +3 -0
- package/esm/message-channel.d.ts +3 -0
- package/esm/message-channel.d.ts.map +1 -0
- package/esm/message-channel.js +13 -0
- package/esm/mod.d.ts +1 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -0
- package/esm/types.d.ts +33 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +1 -0
- package/esm/worker-main.d.ts +84 -0
- package/esm/worker-main.d.ts.map +1 -0
- package/esm/worker-main.js +186 -0
- package/esm/worker.d.ts +2 -74
- package/esm/worker.d.ts.map +1 -1
- package/esm/worker.js +4 -120
- package/package.json +6 -1
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +60 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +49 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +24 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.js +49 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +16 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.js +25 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +26 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +34 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +17 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.js +222 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +35 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.js +62 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.js +30 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +15 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.js +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/false.js +25 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.js +55 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +25 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.js +56 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts +19 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less.js +31 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/match.js +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +44 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.js +61 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +21 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.js +36 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.js +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +35 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.js +170 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +42 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.js +56 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +24 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +61 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.js +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +45 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.js +47 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +15 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +15 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.js +23 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +80 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.js +121 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +140 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.js +283 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +99 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.js +188 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts +29 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/format.js +106 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +159 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.js +252 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts +25 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/types.js +4 -0
- package/script/message-channel.d.ts +3 -0
- package/script/message-channel.d.ts.map +1 -0
- package/script/message-channel.js +16 -0
- package/script/mod.d.ts +1 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +1 -0
- package/script/types.d.ts +33 -0
- package/script/types.d.ts.map +1 -0
- package/script/types.js +2 -0
- package/script/worker-main.d.ts +84 -0
- package/script/worker-main.d.ts.map +1 -0
- package/script/worker-main.js +190 -0
- package/script/worker.d.ts +2 -74
- package/script/worker.d.ts.map +1 -1
- package/script/worker.js +5 -122
package/script/worker.d.ts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
import { type Operation } from "effection";
|
|
2
|
-
export interface WorkerResource<TSend, TRecv, TReturn> extends Operation<TReturn> {
|
|
3
|
-
send(data: TSend): Operation<TRecv>;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Object that represents messages the main thread
|
|
7
|
-
* sends to the worker. It provides function for
|
|
8
|
-
* handling messages.
|
|
9
|
-
*
|
|
10
|
-
* @template TSend - value main thread will send to the worker
|
|
11
|
-
* @template TRecv - value main thread will receive from the worker
|
|
12
|
-
*/
|
|
13
|
-
export interface WorkerMessages<TSend, TRecv> {
|
|
14
|
-
forEach(fn: (message: TSend) => Operation<TRecv>): Operation<void>;
|
|
15
|
-
}
|
|
16
2
|
/**
|
|
17
3
|
* Argument received by workerMain function
|
|
18
4
|
*
|
|
@@ -20,67 +6,9 @@ export interface WorkerMessages<TSend, TRecv> {
|
|
|
20
6
|
* @template TRecv - value main thread will receive from the worker
|
|
21
7
|
* @template TData - data passed from the main thread to the worker during initialization
|
|
22
8
|
*/
|
|
23
|
-
export interface
|
|
24
|
-
|
|
25
|
-
* Namespace that provides APIs for working with incoming messages
|
|
26
|
-
*/
|
|
27
|
-
messages: WorkerMessages<TSend, TRecv>;
|
|
28
|
-
/**
|
|
29
|
-
* Initial data received by the worker from the main thread used for initialization.
|
|
30
|
-
*/
|
|
31
|
-
data: TData;
|
|
9
|
+
export interface WorkerResource<TSend, TRecv, TReturn> extends Operation<TReturn> {
|
|
10
|
+
send(data: TSend): Operation<TRecv>;
|
|
32
11
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Entrypoint used in the worker that estaliblishes communication
|
|
35
|
-
* with the main thread. It can be used to return a value,
|
|
36
|
-
* respond to messages or both.
|
|
37
|
-
*
|
|
38
|
-
* @example Returning a value
|
|
39
|
-
* ```ts
|
|
40
|
-
* import { workerMain } from "../worker.ts";
|
|
41
|
-
*
|
|
42
|
-
* await workerMain(function* ({ data }) {
|
|
43
|
-
* return data;
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @example Responding to messages
|
|
48
|
-
* ```ts
|
|
49
|
-
* import { workerMain } from "../worker.ts";
|
|
50
|
-
*
|
|
51
|
-
* await workerMain(function* ({ messages }) {
|
|
52
|
-
* yield* messages.forEach(function* (message) {
|
|
53
|
-
* return message;
|
|
54
|
-
* });
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example Responding to messages and return a value
|
|
59
|
-
* ```ts
|
|
60
|
-
* import { workerMain } from "../worker.ts";
|
|
61
|
-
*
|
|
62
|
-
* await workerMain<number, number, number, number>(
|
|
63
|
-
* function* ({ messages, data: initial }) {
|
|
64
|
-
* let counter = initial;
|
|
65
|
-
*
|
|
66
|
-
* yield* messages.forEach(function* (message) {
|
|
67
|
-
* counter += message;
|
|
68
|
-
* return counter; // returns a value after each message
|
|
69
|
-
* });
|
|
70
|
-
*
|
|
71
|
-
* return counter; // returns the final value
|
|
72
|
-
* },
|
|
73
|
-
* );
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* @template TSend - value main thread will send to the worker
|
|
77
|
-
* @template TRecv - value main thread will receive from the worker
|
|
78
|
-
* @template TReturn - worker operation return value
|
|
79
|
-
* @template TData - data passed from the main thread to the worker during initialization
|
|
80
|
-
* @param {(options: WorkerMainOptions<TSend, TRecv, TData>) => Operation<TReturn>} body
|
|
81
|
-
* @returns {Promise<void>}
|
|
82
|
-
*/
|
|
83
|
-
export declare function workerMain<TSend, TRecv, TReturn, TData>(body: (options: WorkerMainOptions<TSend, TRecv, TData>) => Operation<TReturn>): Promise<void>;
|
|
84
12
|
/**
|
|
85
13
|
* Use on the main thread to create and exeecute a well behaved web worker.
|
|
86
14
|
*
|
package/script/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,SAAS,EAKf,MAAM,WAAW,CAAC;AAInB;;;;;;GAMG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CACnD,SAAQ,SAAS,CAAC,OAAO,CAAC;IAC1B,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EACpD,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,OAAO,CAAC,EAAE,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GACzC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAgElD"}
|
package/script/worker.js
CHANGED
|
@@ -1,114 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.workerMain = workerMain;
|
|
4
3
|
exports.useWorker = useWorker;
|
|
5
|
-
const
|
|
4
|
+
const mod_js_1 = require("./deps/jsr.io/@std/assert/1.0.16/mod.js");
|
|
6
5
|
const effection_1 = require("effection");
|
|
7
|
-
|
|
8
|
-
* Entrypoint used in the worker that estaliblishes communication
|
|
9
|
-
* with the main thread. It can be used to return a value,
|
|
10
|
-
* respond to messages or both.
|
|
11
|
-
*
|
|
12
|
-
* @example Returning a value
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { workerMain } from "../worker.ts";
|
|
15
|
-
*
|
|
16
|
-
* await workerMain(function* ({ data }) {
|
|
17
|
-
* return data;
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @example Responding to messages
|
|
22
|
-
* ```ts
|
|
23
|
-
* import { workerMain } from "../worker.ts";
|
|
24
|
-
*
|
|
25
|
-
* await workerMain(function* ({ messages }) {
|
|
26
|
-
* yield* messages.forEach(function* (message) {
|
|
27
|
-
* return message;
|
|
28
|
-
* });
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @example Responding to messages and return a value
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { workerMain } from "../worker.ts";
|
|
35
|
-
*
|
|
36
|
-
* await workerMain<number, number, number, number>(
|
|
37
|
-
* function* ({ messages, data: initial }) {
|
|
38
|
-
* let counter = initial;
|
|
39
|
-
*
|
|
40
|
-
* yield* messages.forEach(function* (message) {
|
|
41
|
-
* counter += message;
|
|
42
|
-
* return counter; // returns a value after each message
|
|
43
|
-
* });
|
|
44
|
-
*
|
|
45
|
-
* return counter; // returns the final value
|
|
46
|
-
* },
|
|
47
|
-
* );
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @template TSend - value main thread will send to the worker
|
|
51
|
-
* @template TRecv - value main thread will receive from the worker
|
|
52
|
-
* @template TReturn - worker operation return value
|
|
53
|
-
* @template TData - data passed from the main thread to the worker during initialization
|
|
54
|
-
* @param {(options: WorkerMainOptions<TSend, TRecv, TData>) => Operation<TReturn>} body
|
|
55
|
-
* @returns {Promise<void>}
|
|
56
|
-
*/
|
|
57
|
-
async function workerMain(body) {
|
|
58
|
-
await (0, effection_1.main)(function* () {
|
|
59
|
-
let sent = (0, effection_1.createSignal)();
|
|
60
|
-
let controls = yield* (0, effection_1.on)(self, "message");
|
|
61
|
-
let outcome = (0, effection_1.withResolvers)();
|
|
62
|
-
self.postMessage({ type: "open" });
|
|
63
|
-
let result = yield* (0, effection_1.scoped)(function* () {
|
|
64
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
65
|
-
let next = yield* controls.next();
|
|
66
|
-
while (true) {
|
|
67
|
-
let control = next.value.data;
|
|
68
|
-
if (control.type === "init") {
|
|
69
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
70
|
-
try {
|
|
71
|
-
let value = yield* body({
|
|
72
|
-
data: control.data,
|
|
73
|
-
messages: {
|
|
74
|
-
*forEach(fn) {
|
|
75
|
-
for (let { value, response } of yield* (0, effection_1.each)(sent)) {
|
|
76
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
77
|
-
try {
|
|
78
|
-
let result = yield* fn(value);
|
|
79
|
-
response.postMessage((0, effection_1.Ok)(result));
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
response.postMessage((0, effection_1.Err)(error));
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
yield* effection_1.each.next();
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
outcome.resolve((0, effection_1.Ok)(value));
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
outcome.resolve((0, effection_1.Err)(error));
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else if (control.type === "send") {
|
|
98
|
-
let { value, response } = control;
|
|
99
|
-
sent.send({ value, response });
|
|
100
|
-
}
|
|
101
|
-
else if (control.type === "close") {
|
|
102
|
-
outcome.resolve((0, effection_1.Err)(new Error(`worker terminated`)));
|
|
103
|
-
}
|
|
104
|
-
next = yield* controls.next();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
return yield* outcome.operation;
|
|
108
|
-
});
|
|
109
|
-
self.postMessage({ type: "close", result });
|
|
110
|
-
});
|
|
111
|
-
}
|
|
6
|
+
const message_channel_js_1 = require("./message-channel.js");
|
|
112
7
|
/**
|
|
113
8
|
* Use on the main thread to create and exeecute a well behaved web worker.
|
|
114
9
|
*
|
|
@@ -175,7 +70,7 @@ function useWorker(url, options) {
|
|
|
175
70
|
};
|
|
176
71
|
worker.addEventListener("message", onclose);
|
|
177
72
|
let first = yield* subscription.next();
|
|
178
|
-
(0,
|
|
73
|
+
(0, mod_js_1.assert)(first.value.data.type === "open", `expected first message to arrive from worker to be of type "open", but was: ${first.value.data.type}`);
|
|
179
74
|
yield* (0, effection_1.spawn)(function* () {
|
|
180
75
|
let event = yield* (0, effection_1.once)(worker, "error");
|
|
181
76
|
event.preventDefault();
|
|
@@ -188,7 +83,7 @@ function useWorker(url, options) {
|
|
|
188
83
|
});
|
|
189
84
|
yield* provide({
|
|
190
85
|
*send(value) {
|
|
191
|
-
let channel = yield* useMessageChannel();
|
|
86
|
+
let channel = yield* (0, message_channel_js_1.useMessageChannel)();
|
|
192
87
|
worker.postMessage({
|
|
193
88
|
type: "send",
|
|
194
89
|
value,
|
|
@@ -214,24 +109,12 @@ function useWorker(url, options) {
|
|
|
214
109
|
}
|
|
215
110
|
});
|
|
216
111
|
}
|
|
217
|
-
function useMessageChannel() {
|
|
218
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
219
|
-
let channel = new MessageChannel();
|
|
220
|
-
try {
|
|
221
|
-
yield* provide(channel);
|
|
222
|
-
}
|
|
223
|
-
finally {
|
|
224
|
-
channel.port1.close();
|
|
225
|
-
channel.port2.close();
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
112
|
function settled(operation) {
|
|
230
113
|
return {
|
|
231
114
|
*[Symbol.iterator]() {
|
|
232
115
|
try {
|
|
233
116
|
yield* operation;
|
|
234
|
-
return (0, effection_1.Ok)();
|
|
117
|
+
return (0, effection_1.Ok)(void 0);
|
|
235
118
|
}
|
|
236
119
|
catch (error) {
|
|
237
120
|
return (0, effection_1.Err)(error);
|