@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.
Files changed (241) hide show
  1. package/esm/_dnt.shims.d.ts +2 -0
  2. package/esm/_dnt.shims.d.ts.map +1 -0
  3. package/esm/_dnt.shims.js +57 -0
  4. package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +29 -0
  5. package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +1 -0
  6. package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +46 -0
  7. package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +24 -0
  8. package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.js +46 -0
  10. package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +16 -0
  11. package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@std/assert/1.0.16/assert.js +22 -0
  13. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +26 -0
  14. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +30 -0
  16. package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +17 -0
  17. package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@std/assert/1.0.16/equal.js +186 -0
  19. package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +35 -0
  20. package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@std/assert/1.0.16/equals.js +59 -0
  22. package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +18 -0
  23. package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@std/assert/1.0.16/exists.js +27 -0
  25. package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +15 -0
  26. package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@std/assert/1.0.16/fail.js +20 -0
  28. package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts +18 -0
  29. package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@std/assert/1.0.16/false.js +22 -0
  31. package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +20 -0
  32. package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@std/assert/1.0.16/greater.js +29 -0
  34. package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +20 -0
  35. package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +29 -0
  37. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +23 -0
  38. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.js +52 -0
  40. package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +25 -0
  41. package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.js +53 -0
  43. package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts +19 -0
  44. package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@std/assert/1.0.16/less.js +28 -0
  46. package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +20 -0
  47. package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +29 -0
  49. package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts +18 -0
  50. package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@std/assert/1.0.16/match.js +26 -0
  52. package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +44 -0
  53. package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@std/assert/1.0.16/mod.js +45 -0
  55. package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +21 -0
  56. package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.js +33 -0
  58. package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +20 -0
  59. package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +1 -0
  60. package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +29 -0
  61. package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +18 -0
  62. package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +1 -0
  63. package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.js +26 -0
  64. package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +23 -0
  65. package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +1 -0
  66. package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +32 -0
  67. package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +29 -0
  68. package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +1 -0
  69. package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.js +167 -0
  70. package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +42 -0
  71. package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +1 -0
  72. package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.js +53 -0
  73. package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +24 -0
  74. package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +1 -0
  75. package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +58 -0
  76. package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +18 -0
  77. package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +1 -0
  78. package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.js +26 -0
  79. package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +45 -0
  80. package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +1 -0
  81. package/esm/deps/jsr.io/@std/assert/1.0.16/throws.js +44 -0
  82. package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +15 -0
  83. package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +1 -0
  84. package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +20 -0
  85. package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +15 -0
  86. package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +1 -0
  87. package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.js +20 -0
  88. package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +80 -0
  89. package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +1 -0
  90. package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.js +116 -0
  91. package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +140 -0
  92. package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +1 -0
  93. package/esm/deps/jsr.io/@std/internal/1.0.12/diff.js +276 -0
  94. package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +99 -0
  95. package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +1 -0
  96. package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.js +182 -0
  97. package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts +29 -0
  98. package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +1 -0
  99. package/esm/deps/jsr.io/@std/internal/1.0.12/format.js +70 -0
  100. package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +159 -0
  101. package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +1 -0
  102. package/esm/deps/jsr.io/@std/internal/1.0.12/styles.js +207 -0
  103. package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts +25 -0
  104. package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +1 -0
  105. package/esm/deps/jsr.io/@std/internal/1.0.12/types.js +3 -0
  106. package/esm/message-channel.d.ts +3 -0
  107. package/esm/message-channel.d.ts.map +1 -0
  108. package/esm/message-channel.js +13 -0
  109. package/esm/mod.d.ts +1 -0
  110. package/esm/mod.d.ts.map +1 -1
  111. package/esm/mod.js +1 -0
  112. package/esm/types.d.ts +33 -0
  113. package/esm/types.d.ts.map +1 -0
  114. package/esm/types.js +1 -0
  115. package/esm/worker-main.d.ts +84 -0
  116. package/esm/worker-main.d.ts.map +1 -0
  117. package/esm/worker-main.js +186 -0
  118. package/esm/worker.d.ts +2 -74
  119. package/esm/worker.d.ts.map +1 -1
  120. package/esm/worker.js +4 -120
  121. package/package.json +6 -1
  122. package/script/_dnt.shims.d.ts +2 -0
  123. package/script/_dnt.shims.d.ts.map +1 -0
  124. package/script/_dnt.shims.js +60 -0
  125. package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts +29 -0
  126. package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +1 -0
  127. package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.js +49 -0
  128. package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts +24 -0
  129. package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +1 -0
  130. package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.js +49 -0
  131. package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts +16 -0
  132. package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +1 -0
  133. package/script/deps/jsr.io/@std/assert/1.0.16/assert.js +25 -0
  134. package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +26 -0
  135. package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +1 -0
  136. package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +34 -0
  137. package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts +17 -0
  138. package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +1 -0
  139. package/script/deps/jsr.io/@std/assert/1.0.16/equal.js +222 -0
  140. package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts +35 -0
  141. package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +1 -0
  142. package/script/deps/jsr.io/@std/assert/1.0.16/equals.js +62 -0
  143. package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts +18 -0
  144. package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +1 -0
  145. package/script/deps/jsr.io/@std/assert/1.0.16/exists.js +30 -0
  146. package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts +15 -0
  147. package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +1 -0
  148. package/script/deps/jsr.io/@std/assert/1.0.16/fail.js +23 -0
  149. package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts +18 -0
  150. package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +1 -0
  151. package/script/deps/jsr.io/@std/assert/1.0.16/false.js +25 -0
  152. package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts +20 -0
  153. package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +1 -0
  154. package/script/deps/jsr.io/@std/assert/1.0.16/greater.js +32 -0
  155. package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts +20 -0
  156. package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +1 -0
  157. package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.js +32 -0
  158. package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +23 -0
  159. package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +1 -0
  160. package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.js +55 -0
  161. package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts +25 -0
  162. package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +1 -0
  163. package/script/deps/jsr.io/@std/assert/1.0.16/is_error.js +56 -0
  164. package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts +19 -0
  165. package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +1 -0
  166. package/script/deps/jsr.io/@std/assert/1.0.16/less.js +31 -0
  167. package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts +20 -0
  168. package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +1 -0
  169. package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.js +32 -0
  170. package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts +18 -0
  171. package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +1 -0
  172. package/script/deps/jsr.io/@std/assert/1.0.16/match.js +29 -0
  173. package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts +44 -0
  174. package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +1 -0
  175. package/script/deps/jsr.io/@std/assert/1.0.16/mod.js +61 -0
  176. package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts +21 -0
  177. package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +1 -0
  178. package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.js +36 -0
  179. package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts +20 -0
  180. package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +1 -0
  181. package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.js +32 -0
  182. package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts +18 -0
  183. package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +1 -0
  184. package/script/deps/jsr.io/@std/assert/1.0.16/not_match.js +29 -0
  185. package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts +23 -0
  186. package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +1 -0
  187. package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.js +35 -0
  188. package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts +29 -0
  189. package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +1 -0
  190. package/script/deps/jsr.io/@std/assert/1.0.16/object_match.js +170 -0
  191. package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts +42 -0
  192. package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +1 -0
  193. package/script/deps/jsr.io/@std/assert/1.0.16/rejects.js +56 -0
  194. package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts +24 -0
  195. package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +1 -0
  196. package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.js +61 -0
  197. package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts +18 -0
  198. package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +1 -0
  199. package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.js +29 -0
  200. package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts +45 -0
  201. package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +1 -0
  202. package/script/deps/jsr.io/@std/assert/1.0.16/throws.js +47 -0
  203. package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts +15 -0
  204. package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +1 -0
  205. package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.js +23 -0
  206. package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts +15 -0
  207. package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +1 -0
  208. package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.js +23 -0
  209. package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts +80 -0
  210. package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +1 -0
  211. package/script/deps/jsr.io/@std/internal/1.0.12/build_message.js +121 -0
  212. package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts +140 -0
  213. package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +1 -0
  214. package/script/deps/jsr.io/@std/internal/1.0.12/diff.js +283 -0
  215. package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts +99 -0
  216. package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +1 -0
  217. package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.js +188 -0
  218. package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts +29 -0
  219. package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +1 -0
  220. package/script/deps/jsr.io/@std/internal/1.0.12/format.js +106 -0
  221. package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts +159 -0
  222. package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +1 -0
  223. package/script/deps/jsr.io/@std/internal/1.0.12/styles.js +252 -0
  224. package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts +25 -0
  225. package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +1 -0
  226. package/script/deps/jsr.io/@std/internal/1.0.12/types.js +4 -0
  227. package/script/message-channel.d.ts +3 -0
  228. package/script/message-channel.d.ts.map +1 -0
  229. package/script/message-channel.js +16 -0
  230. package/script/mod.d.ts +1 -0
  231. package/script/mod.d.ts.map +1 -1
  232. package/script/mod.js +1 -0
  233. package/script/types.d.ts +33 -0
  234. package/script/types.d.ts.map +1 -0
  235. package/script/types.js +2 -0
  236. package/script/worker-main.d.ts +84 -0
  237. package/script/worker-main.d.ts.map +1 -0
  238. package/script/worker-main.js +190 -0
  239. package/script/worker.d.ts +2 -74
  240. package/script/worker.d.ts.map +1 -1
  241. package/script/worker.js +5 -122
@@ -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 WorkerMainOptions<TSend, TRecv, TData> {
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
  *
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAQL,KAAK,SAAS,EAMf,MAAM,WAAW,CAAC;AAEnB,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;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,EAAE,KAAK;IAC1C,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;CACpE;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK;IACpD;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACvC;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC;CACb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAC3D,IAAI,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,SAAS,CAAC,OAAO,CAAC,GAC5E,OAAO,CAAC,IAAI,CAAC,CAsDf;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"}
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 assert_1 = require("@std/assert");
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, assert_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}`);
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);