@effectionx/worker 0.3.1 → 0.4.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/dist/message-channel.d.ts.map +1 -0
- package/dist/mod.d.ts +4 -0
- package/dist/mod.d.ts.map +1 -0
- package/{esm → dist}/mod.js +1 -0
- package/dist/test-simple-worker.d.ts +2 -0
- package/dist/test-simple-worker.d.ts.map +1 -0
- package/dist/test-simple-worker.js +11 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts.map +1 -0
- package/{esm → dist}/worker-main.d.ts +1 -1
- package/dist/worker-main.d.ts.map +1 -0
- package/{esm → dist}/worker-main.js +34 -16
- package/dist/worker.d.ts.map +1 -0
- package/{esm → dist}/worker.js +3 -4
- package/message-channel.ts +13 -0
- package/mod.ts +3 -0
- package/package.json +22 -16
- package/test-assets/boom-result-worker.ts +5 -0
- package/test-assets/boom-worker.ts +7 -0
- package/test-assets/counter-worker.ts +15 -0
- package/test-assets/crash-worker.ts +1 -0
- package/test-assets/echo-worker.ts +7 -0
- package/test-assets/result-worker.ts +5 -0
- package/test-assets/shutdown-worker.ts +24 -0
- package/test-assets/suspend-worker.ts +4 -0
- package/test-simple-worker.ts +12 -0
- package/tsconfig.json +20 -0
- package/types.ts +38 -0
- package/worker-main.ts +248 -0
- package/worker.test.ts +179 -0
- package/worker.ts +159 -0
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +0 -46
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +0 -24
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.js +0 -46
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +0 -16
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.js +0 -22
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +0 -30
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +0 -17
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.js +0 -186
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +0 -35
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.js +0 -59
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.js +0 -27
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +0 -15
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.js +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.js +0 -22
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +0 -23
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.js +0 -52
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +0 -25
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.js +0 -53
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts +0 -19
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.js +0 -28
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.js +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +0 -44
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.js +0 -45
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +0 -21
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.js +0 -33
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.js +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +0 -23
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +0 -32
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +0 -29
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.js +0 -167
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +0 -42
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.js +0 -53
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +0 -24
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +0 -58
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +0 -18
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.js +0 -26
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +0 -45
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.js +0 -44
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +0 -15
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +0 -20
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +0 -15
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.js +0 -20
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +0 -80
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.js +0 -116
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +0 -140
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.js +0 -276
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +0 -99
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.js +0 -182
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts +0 -29
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.js +0 -70
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +0 -159
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.js +0 -207
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts +0 -25
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.js +0 -3
- package/esm/message-channel.d.ts.map +0 -1
- package/esm/mod.d.ts +0 -3
- package/esm/mod.d.ts.map +0 -1
- package/esm/package.json +0 -3
- package/esm/types.d.ts.map +0 -1
- package/esm/worker-main.d.ts.map +0 -1
- package/esm/worker.d.ts.map +0 -1
- package/script/_dnt.shims.d.ts +0 -2
- package/script/_dnt.shims.d.ts.map +0 -1
- package/script/_dnt.shims.js +0 -60
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +0 -49
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +0 -24
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.js +0 -49
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +0 -16
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.js +0 -25
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +0 -26
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +0 -34
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +0 -17
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.js +0 -222
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +0 -35
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.js +0 -62
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.js +0 -30
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +0 -15
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.js +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/false.js +0 -25
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.js +0 -55
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +0 -25
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.js +0 -56
- package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts +0 -19
- package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/less.js +0 -31
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/match.js +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +0 -44
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.js +0 -61
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +0 -21
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.js +0 -36
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +0 -20
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +0 -32
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.js +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +0 -35
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.js +0 -170
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +0 -42
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.js +0 -56
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +0 -24
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +0 -61
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +0 -18
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.js +0 -29
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +0 -45
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.js +0 -47
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +0 -15
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +0 -23
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +0 -15
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.js +0 -23
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +0 -80
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.js +0 -121
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +0 -140
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.js +0 -283
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +0 -99
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.js +0 -188
- package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts +0 -29
- package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/format.js +0 -106
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +0 -159
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.js +0 -252
- package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts +0 -25
- package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.12/types.js +0 -4
- package/script/message-channel.d.ts +0 -3
- package/script/message-channel.d.ts.map +0 -1
- package/script/message-channel.js +0 -16
- package/script/mod.d.ts +0 -3
- package/script/mod.d.ts.map +0 -1
- package/script/mod.js +0 -18
- package/script/package.json +0 -3
- package/script/types.d.ts +0 -33
- package/script/types.d.ts.map +0 -1
- package/script/types.js +0 -2
- package/script/worker-main.d.ts +0 -84
- package/script/worker-main.d.ts.map +0 -1
- package/script/worker-main.js +0 -190
- package/script/worker.d.ts +0 -63
- package/script/worker.d.ts.map +0 -1
- package/script/worker.js +0 -124
- /package/{esm → dist}/message-channel.d.ts +0 -0
- /package/{esm → dist}/message-channel.js +0 -0
- /package/{esm → dist}/types.d.ts +0 -0
- /package/{esm → dist}/types.js +0 -0
- /package/{esm → dist}/worker.d.ts +0 -0
package/script/worker.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { type Operation } from "effection";
|
|
2
|
-
/**
|
|
3
|
-
* Argument received by workerMain function
|
|
4
|
-
*
|
|
5
|
-
* @template TSend - value main thread will send to the worker
|
|
6
|
-
* @template TRecv - value main thread will receive from the worker
|
|
7
|
-
* @template TData - data passed from the main thread to the worker during initialization
|
|
8
|
-
*/
|
|
9
|
-
export interface WorkerResource<TSend, TRecv, TReturn> extends Operation<TReturn> {
|
|
10
|
-
send(data: TSend): Operation<TRecv>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Use on the main thread to create and exeecute a well behaved web worker.
|
|
14
|
-
*
|
|
15
|
-
* @example Compute a single value
|
|
16
|
-
* ```ts
|
|
17
|
-
* import { run } from "effection";
|
|
18
|
-
* import { useWorker } from "@effectionx/worker"
|
|
19
|
-
*
|
|
20
|
-
* await run(function*() {
|
|
21
|
-
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
22
|
-
*
|
|
23
|
-
* try {
|
|
24
|
-
* const result = yield* worker;
|
|
25
|
-
* } catch (e) {
|
|
26
|
-
* console.error(e);
|
|
27
|
-
* }
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example Compute multipe values
|
|
32
|
-
* ```ts
|
|
33
|
-
* import { run } from "effection";
|
|
34
|
-
* import { useWorker } from "@effectionx/worker"
|
|
35
|
-
*
|
|
36
|
-
* await run(function*() {
|
|
37
|
-
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
38
|
-
*
|
|
39
|
-
* try {
|
|
40
|
-
* const result1 = yield* worker.send("Tom");
|
|
41
|
-
* const result2 = yield* worker.send("Dick");
|
|
42
|
-
* const result2 = yield* worker.send("Harry");
|
|
43
|
-
*
|
|
44
|
-
* // get the last result
|
|
45
|
-
* const finalResult = yield* worker;
|
|
46
|
-
* } catch (e) {
|
|
47
|
-
* console.error(e);
|
|
48
|
-
* }
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param url URL or string of script
|
|
53
|
-
* @param options WorkerOptions
|
|
54
|
-
* @template TSend - value main thread will send to the worker
|
|
55
|
-
* @template TRecv - value main thread will receive from the worker
|
|
56
|
-
* @template TReturn - worker operation return value
|
|
57
|
-
* @template TData - data passed from the main thread to the worker during initialization
|
|
58
|
-
* @returns {Operation<WorkerResource<TSend, TRecv>>}
|
|
59
|
-
*/
|
|
60
|
-
export declare function useWorker<TSend, TRecv, TReturn, TData>(url: string | URL, options?: WorkerOptions & {
|
|
61
|
-
data?: TData;
|
|
62
|
-
}): Operation<WorkerResource<TSend, TRecv, TReturn>>;
|
|
63
|
-
//# sourceMappingURL=worker.d.ts.map
|
package/script/worker.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useWorker = useWorker;
|
|
4
|
-
const mod_js_1 = require("./deps/jsr.io/@std/assert/1.0.16/mod.js");
|
|
5
|
-
const effection_1 = require("effection");
|
|
6
|
-
const message_channel_js_1 = require("./message-channel.js");
|
|
7
|
-
/**
|
|
8
|
-
* Use on the main thread to create and exeecute a well behaved web worker.
|
|
9
|
-
*
|
|
10
|
-
* @example Compute a single value
|
|
11
|
-
* ```ts
|
|
12
|
-
* import { run } from "effection";
|
|
13
|
-
* import { useWorker } from "@effectionx/worker"
|
|
14
|
-
*
|
|
15
|
-
* await run(function*() {
|
|
16
|
-
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
17
|
-
*
|
|
18
|
-
* try {
|
|
19
|
-
* const result = yield* worker;
|
|
20
|
-
* } catch (e) {
|
|
21
|
-
* console.error(e);
|
|
22
|
-
* }
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @example Compute multipe values
|
|
27
|
-
* ```ts
|
|
28
|
-
* import { run } from "effection";
|
|
29
|
-
* import { useWorker } from "@effectionx/worker"
|
|
30
|
-
*
|
|
31
|
-
* await run(function*() {
|
|
32
|
-
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
33
|
-
*
|
|
34
|
-
* try {
|
|
35
|
-
* const result1 = yield* worker.send("Tom");
|
|
36
|
-
* const result2 = yield* worker.send("Dick");
|
|
37
|
-
* const result2 = yield* worker.send("Harry");
|
|
38
|
-
*
|
|
39
|
-
* // get the last result
|
|
40
|
-
* const finalResult = yield* worker;
|
|
41
|
-
* } catch (e) {
|
|
42
|
-
* console.error(e);
|
|
43
|
-
* }
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @param url URL or string of script
|
|
48
|
-
* @param options WorkerOptions
|
|
49
|
-
* @template TSend - value main thread will send to the worker
|
|
50
|
-
* @template TRecv - value main thread will receive from the worker
|
|
51
|
-
* @template TReturn - worker operation return value
|
|
52
|
-
* @template TData - data passed from the main thread to the worker during initialization
|
|
53
|
-
* @returns {Operation<WorkerResource<TSend, TRecv>>}
|
|
54
|
-
*/
|
|
55
|
-
function useWorker(url, options) {
|
|
56
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
57
|
-
let outcome = (0, effection_1.withResolvers)();
|
|
58
|
-
let worker = new Worker(url, options);
|
|
59
|
-
let subscription = yield* (0, effection_1.on)(worker, "message");
|
|
60
|
-
let onclose = (event) => {
|
|
61
|
-
if (event.data.type === "close") {
|
|
62
|
-
let { result } = event.data;
|
|
63
|
-
if (result.ok) {
|
|
64
|
-
outcome.resolve(result.value);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
outcome.reject(result.error);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
worker.addEventListener("message", onclose);
|
|
72
|
-
let first = yield* subscription.next();
|
|
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}`);
|
|
74
|
-
yield* (0, effection_1.spawn)(function* () {
|
|
75
|
-
let event = yield* (0, effection_1.once)(worker, "error");
|
|
76
|
-
event.preventDefault();
|
|
77
|
-
throw event.error;
|
|
78
|
-
});
|
|
79
|
-
try {
|
|
80
|
-
worker.postMessage({
|
|
81
|
-
type: "init",
|
|
82
|
-
data: options?.data,
|
|
83
|
-
});
|
|
84
|
-
yield* provide({
|
|
85
|
-
*send(value) {
|
|
86
|
-
let channel = yield* (0, message_channel_js_1.useMessageChannel)();
|
|
87
|
-
worker.postMessage({
|
|
88
|
-
type: "send",
|
|
89
|
-
value,
|
|
90
|
-
response: channel.port2,
|
|
91
|
-
}, [channel.port2]);
|
|
92
|
-
channel.port1.start();
|
|
93
|
-
let event = yield* (0, effection_1.once)(channel.port1, "message");
|
|
94
|
-
let result = event.data;
|
|
95
|
-
if (result.ok) {
|
|
96
|
-
return result.value;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
throw result.error;
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
[Symbol.iterator]: outcome.operation[Symbol.iterator],
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
finally {
|
|
106
|
-
worker.postMessage({ type: "close" });
|
|
107
|
-
yield* settled(outcome.operation);
|
|
108
|
-
worker.removeEventListener("message", onclose);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function settled(operation) {
|
|
113
|
-
return {
|
|
114
|
-
*[Symbol.iterator]() {
|
|
115
|
-
try {
|
|
116
|
-
yield* operation;
|
|
117
|
-
return (0, effection_1.Ok)(void 0);
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
return (0, effection_1.Err)(error);
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
File without changes
|
|
File without changes
|
/package/{esm → dist}/types.d.ts
RENAMED
|
File without changes
|
/package/{esm → dist}/types.js
RENAMED
|
File without changes
|
|
File without changes
|