@typed/fx 0.0.4 → 0.0.8

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 (461) hide show
  1. package/.eslintcache +1 -1
  2. package/cjs/Cause/Cause.d.ts +10 -0
  3. package/cjs/Cause/Cause.d.ts.map +1 -1
  4. package/cjs/Cause/Cause.js +37 -2
  5. package/cjs/Cause/Cause.js.map +1 -1
  6. package/cjs/Cause/Renderer.js +1 -1
  7. package/cjs/Cause/Renderer.js.map +1 -1
  8. package/cjs/Env/Env.d.ts +9 -1
  9. package/cjs/Env/Env.d.ts.map +1 -1
  10. package/cjs/Env/Env.js +32 -5
  11. package/cjs/Env/Env.js.map +1 -1
  12. package/cjs/Fiber/fromScope.d.ts +5 -0
  13. package/cjs/Fiber/fromScope.d.ts.map +1 -0
  14. package/cjs/Fiber/fromScope.js +17 -0
  15. package/cjs/Fiber/fromScope.js.map +1 -0
  16. package/cjs/FiberRef/builtins.d.ts +4 -1
  17. package/cjs/FiberRef/builtins.d.ts.map +1 -1
  18. package/cjs/FiberRef/builtins.js +40 -13
  19. package/cjs/FiberRef/builtins.js.map +1 -1
  20. package/cjs/FiberRuntime/FiberRuntime.d.ts.map +1 -1
  21. package/cjs/FiberRuntime/FiberRuntime.js +23 -14
  22. package/cjs/FiberRuntime/FiberRuntime.js.map +1 -1
  23. package/cjs/Fx/Fx.d.ts +4 -3
  24. package/cjs/Fx/Fx.d.ts.map +1 -1
  25. package/cjs/Fx/Fx.js +25 -24
  26. package/cjs/Fx/Fx.js.map +1 -1
  27. package/cjs/Fx/join.d.ts +1 -1
  28. package/cjs/Fx/join.d.ts.map +1 -1
  29. package/cjs/Fx/join.js +1 -1
  30. package/cjs/Fx/join.js.map +1 -1
  31. package/cjs/Schedule/ScheduleState.d.ts +3 -0
  32. package/cjs/Schedule/ScheduleState.d.ts.map +1 -1
  33. package/cjs/Schedule/ScheduleState.js +3 -0
  34. package/cjs/Schedule/ScheduleState.js.map +1 -1
  35. package/cjs/Scheduler/RootScheduler.d.ts.map +1 -1
  36. package/cjs/Scheduler/RootScheduler.js +4 -5
  37. package/cjs/Scheduler/RootScheduler.js.map +1 -1
  38. package/cjs/Scheduler/Scheduler.d.ts +2 -2
  39. package/cjs/Scheduler/Scheduler.d.ts.map +1 -1
  40. package/cjs/Scheduler/Scheduler.js.map +1 -1
  41. package/cjs/Scheduler/callbackScheduler.d.ts.map +1 -1
  42. package/cjs/Scheduler/callbackScheduler.js +1 -0
  43. package/cjs/Scheduler/callbackScheduler.js.map +1 -1
  44. package/cjs/Scheduler/runSchedule.d.ts +1 -1
  45. package/cjs/Scheduler/runSchedule.d.ts.map +1 -1
  46. package/cjs/Scheduler/runSchedule.js +3 -2
  47. package/cjs/Scheduler/runSchedule.js.map +1 -1
  48. package/cjs/Scope/LocalScope.d.ts.map +1 -1
  49. package/cjs/Scope/LocalScope.js +8 -8
  50. package/cjs/Scope/LocalScope.js.map +1 -1
  51. package/cjs/Semaphore/Semaphore.d.ts +9 -9
  52. package/cjs/Semaphore/Semaphore.d.ts.map +1 -1
  53. package/cjs/Semaphore/Semaphore.js +34 -15
  54. package/cjs/Semaphore/Semaphore.js.map +1 -1
  55. package/cjs/Sink/Sink.d.ts +1 -0
  56. package/cjs/Sink/Sink.d.ts.map +1 -1
  57. package/cjs/Sink/Sink.js +11 -1
  58. package/cjs/Sink/Sink.js.map +1 -1
  59. package/cjs/Stream/Stream.d.ts +5 -14
  60. package/cjs/Stream/Stream.d.ts.map +1 -1
  61. package/cjs/Stream/Stream.js.map +1 -1
  62. package/cjs/Stream/acquirePermit.d.ts +15 -0
  63. package/cjs/Stream/acquirePermit.d.ts.map +1 -0
  64. package/cjs/Stream/acquirePermit.js +43 -0
  65. package/cjs/Stream/acquirePermit.js.map +1 -0
  66. package/cjs/Stream/bimap.d.ts +33 -4
  67. package/cjs/Stream/bimap.d.ts.map +1 -1
  68. package/cjs/Stream/bimap.js +109 -12
  69. package/cjs/Stream/bimap.js.map +1 -1
  70. package/cjs/Stream/continueWith.d.ts +4 -3
  71. package/cjs/Stream/continueWith.d.ts.map +1 -1
  72. package/cjs/Stream/continueWith.js +9 -6
  73. package/cjs/Stream/continueWith.js.map +1 -1
  74. package/cjs/Stream/delay.d.ts +4 -0
  75. package/cjs/Stream/delay.d.ts.map +1 -0
  76. package/cjs/Stream/delay.js +30 -0
  77. package/cjs/Stream/delay.js.map +1 -0
  78. package/cjs/Stream/drain.d.ts +2 -2
  79. package/cjs/Stream/drain.d.ts.map +1 -1
  80. package/cjs/Stream/drain.js +5 -5
  81. package/cjs/Stream/drain.js.map +1 -1
  82. package/cjs/Stream/empty.d.ts.map +1 -1
  83. package/cjs/Stream/empty.js +1 -2
  84. package/cjs/Stream/empty.js.map +1 -1
  85. package/cjs/Stream/flatMap.d.ts +7 -5
  86. package/cjs/Stream/flatMap.d.ts.map +1 -1
  87. package/cjs/Stream/flatMap.js +33 -19
  88. package/cjs/Stream/flatMap.js.map +1 -1
  89. package/cjs/Stream/flatMapConcurrently.d.ts +6 -0
  90. package/cjs/Stream/flatMapConcurrently.d.ts.map +1 -0
  91. package/cjs/Stream/flatMapConcurrently.js +25 -0
  92. package/cjs/Stream/flatMapConcurrently.js.map +1 -0
  93. package/cjs/Stream/flatMapFx.d.ts +5 -1
  94. package/cjs/Stream/flatMapFx.d.ts.map +1 -1
  95. package/cjs/Stream/flatMapFx.js +18 -3
  96. package/cjs/Stream/flatMapFx.js.map +1 -1
  97. package/cjs/Stream/foldMap.d.ts +11 -0
  98. package/cjs/Stream/foldMap.d.ts.map +1 -0
  99. package/cjs/Stream/foldMap.js +67 -0
  100. package/cjs/Stream/foldMap.js.map +1 -0
  101. package/cjs/Stream/fromArray.d.ts +2 -0
  102. package/cjs/Stream/fromArray.d.ts.map +1 -0
  103. package/cjs/Stream/fromArray.js +12 -0
  104. package/cjs/Stream/fromArray.js.map +1 -0
  105. package/cjs/Stream/fromCallback.d.ts +4 -3
  106. package/cjs/Stream/fromCallback.d.ts.map +1 -1
  107. package/cjs/Stream/fromCallback.js +26 -26
  108. package/cjs/Stream/fromCallback.js.map +1 -1
  109. package/cjs/Stream/fromFx.d.ts +23 -8
  110. package/cjs/Stream/fromFx.d.ts.map +1 -1
  111. package/cjs/Stream/fromFx.js +36 -16
  112. package/cjs/Stream/fromFx.js.map +1 -1
  113. package/cjs/Stream/hkt.d.ts +24 -1
  114. package/cjs/Stream/hkt.d.ts.map +1 -1
  115. package/cjs/Stream/hkt.js +43 -5
  116. package/cjs/Stream/hkt.js.map +1 -1
  117. package/cjs/Stream/hold.d.ts +27 -0
  118. package/cjs/Stream/hold.d.ts.map +1 -0
  119. package/cjs/Stream/hold.js +94 -0
  120. package/cjs/Stream/hold.js.map +1 -0
  121. package/cjs/Stream/index.d.ts +14 -1
  122. package/cjs/Stream/index.d.ts.map +1 -1
  123. package/cjs/Stream/index.js +14 -1
  124. package/cjs/Stream/index.js.map +1 -1
  125. package/cjs/Stream/lazy.d.ts +3 -0
  126. package/cjs/Stream/lazy.d.ts.map +1 -0
  127. package/cjs/Stream/lazy.js +9 -0
  128. package/cjs/Stream/lazy.js.map +1 -0
  129. package/cjs/Stream/merge.d.ts +18 -0
  130. package/cjs/Stream/merge.d.ts.map +1 -0
  131. package/cjs/Stream/merge.js +84 -0
  132. package/cjs/Stream/merge.js.map +1 -0
  133. package/cjs/Stream/multicast.d.ts +27 -0
  134. package/cjs/Stream/multicast.d.ts.map +1 -0
  135. package/cjs/Stream/multicast.js +83 -0
  136. package/cjs/Stream/multicast.js.map +1 -0
  137. package/cjs/Stream/orElse.d.ts +17 -0
  138. package/cjs/Stream/orElse.d.ts.map +1 -0
  139. package/cjs/Stream/orElse.js +105 -0
  140. package/cjs/Stream/orElse.js.map +1 -0
  141. package/cjs/Stream/periodic.d.ts +1 -1
  142. package/cjs/Stream/periodic.d.ts.map +1 -1
  143. package/cjs/Stream/periodic.js +1 -1
  144. package/cjs/Stream/periodic.js.map +1 -1
  145. package/cjs/Stream/provide.d.ts +8 -0
  146. package/cjs/Stream/provide.d.ts.map +1 -0
  147. package/cjs/Stream/provide.js +42 -0
  148. package/cjs/Stream/provide.js.map +1 -0
  149. package/cjs/Stream/run.d.ts +2 -2
  150. package/cjs/Stream/run.d.ts.map +1 -1
  151. package/cjs/Stream/run.js +1 -1
  152. package/cjs/Stream/run.js.map +1 -1
  153. package/cjs/Stream/scan.d.ts +17 -0
  154. package/cjs/Stream/scan.d.ts.map +1 -0
  155. package/cjs/Stream/scan.js +32 -0
  156. package/cjs/Stream/scan.js.map +1 -0
  157. package/cjs/Stream/scheduled.d.ts +12 -3
  158. package/cjs/Stream/scheduled.d.ts.map +1 -1
  159. package/cjs/Stream/scheduled.js +23 -5
  160. package/cjs/Stream/scheduled.js.map +1 -1
  161. package/cjs/Stream/setFiberRefLocally.d.ts +15 -0
  162. package/cjs/Stream/setFiberRefLocally.d.ts.map +1 -0
  163. package/cjs/Stream/setFiberRefLocally.js +53 -0
  164. package/cjs/Stream/setFiberRefLocally.js.map +1 -0
  165. package/cjs/Stream/skipRepeats.d.ts +5 -0
  166. package/cjs/Stream/skipRepeats.d.ts.map +1 -0
  167. package/cjs/Stream/skipRepeats.js +36 -0
  168. package/cjs/Stream/skipRepeats.js.map +1 -0
  169. package/cjs/Stream/switchMap.d.ts +18 -0
  170. package/cjs/Stream/switchMap.d.ts.map +1 -0
  171. package/cjs/Stream/switchMap.js +124 -0
  172. package/cjs/Stream/switchMap.js.map +1 -0
  173. package/cjs/Stream/tap.d.ts +2 -1
  174. package/cjs/Stream/tap.d.ts.map +1 -1
  175. package/cjs/Stream/tap.js +4 -2
  176. package/cjs/Stream/tap.js.map +1 -1
  177. package/cjs/Supervisor/index.d.ts +2 -0
  178. package/cjs/Supervisor/index.d.ts.map +1 -1
  179. package/cjs/Supervisor/index.js +2 -0
  180. package/cjs/Supervisor/index.js.map +1 -1
  181. package/cjs/Supervisor/inheritFiberRefs.d.ts +2 -0
  182. package/cjs/Supervisor/inheritFiberRefs.d.ts.map +1 -0
  183. package/cjs/Supervisor/inheritFiberRefs.js +17 -0
  184. package/cjs/Supervisor/inheritFiberRefs.js.map +1 -0
  185. package/cjs/Timeline/index.js.map +1 -1
  186. package/esm/Cause/Cause.d.ts +10 -0
  187. package/esm/Cause/Cause.d.ts.map +1 -1
  188. package/esm/Cause/Cause.js +27 -0
  189. package/esm/Cause/Cause.js.map +1 -1
  190. package/esm/Cause/Renderer.js +1 -1
  191. package/esm/Cause/Renderer.js.map +1 -1
  192. package/esm/Env/Env.d.ts +9 -1
  193. package/esm/Env/Env.d.ts.map +1 -1
  194. package/esm/Env/Env.js +8 -5
  195. package/esm/Env/Env.js.map +1 -1
  196. package/esm/Fiber/fromScope.d.ts +5 -0
  197. package/esm/Fiber/fromScope.d.ts.map +1 -0
  198. package/esm/Fiber/fromScope.js +13 -0
  199. package/esm/Fiber/fromScope.js.map +1 -0
  200. package/esm/FiberRef/builtins.d.ts +4 -1
  201. package/esm/FiberRef/builtins.d.ts.map +1 -1
  202. package/esm/FiberRef/builtins.js +36 -12
  203. package/esm/FiberRef/builtins.js.map +1 -1
  204. package/esm/FiberRuntime/FiberRuntime.d.ts.map +1 -1
  205. package/esm/FiberRuntime/FiberRuntime.js +23 -14
  206. package/esm/FiberRuntime/FiberRuntime.js.map +1 -1
  207. package/esm/Fx/Fx.d.ts +4 -3
  208. package/esm/Fx/Fx.d.ts.map +1 -1
  209. package/esm/Fx/Fx.js +22 -22
  210. package/esm/Fx/Fx.js.map +1 -1
  211. package/esm/Fx/join.d.ts +1 -1
  212. package/esm/Fx/join.d.ts.map +1 -1
  213. package/esm/Fx/join.js +1 -1
  214. package/esm/Fx/join.js.map +1 -1
  215. package/esm/Schedule/ScheduleState.d.ts +3 -0
  216. package/esm/Schedule/ScheduleState.d.ts.map +1 -1
  217. package/esm/Schedule/ScheduleState.js +3 -0
  218. package/esm/Schedule/ScheduleState.js.map +1 -1
  219. package/esm/Scheduler/RootScheduler.d.ts.map +1 -1
  220. package/esm/Scheduler/RootScheduler.js +4 -5
  221. package/esm/Scheduler/RootScheduler.js.map +1 -1
  222. package/esm/Scheduler/Scheduler.d.ts +2 -2
  223. package/esm/Scheduler/Scheduler.d.ts.map +1 -1
  224. package/esm/Scheduler/Scheduler.js.map +1 -1
  225. package/esm/Scheduler/callbackScheduler.d.ts.map +1 -1
  226. package/esm/Scheduler/callbackScheduler.js +1 -0
  227. package/esm/Scheduler/callbackScheduler.js.map +1 -1
  228. package/esm/Scheduler/runSchedule.d.ts +1 -1
  229. package/esm/Scheduler/runSchedule.d.ts.map +1 -1
  230. package/esm/Scheduler/runSchedule.js +4 -3
  231. package/esm/Scheduler/runSchedule.js.map +1 -1
  232. package/esm/Scope/LocalScope.d.ts.map +1 -1
  233. package/esm/Scope/LocalScope.js +8 -8
  234. package/esm/Scope/LocalScope.js.map +1 -1
  235. package/esm/Semaphore/Semaphore.d.ts +9 -9
  236. package/esm/Semaphore/Semaphore.d.ts.map +1 -1
  237. package/esm/Semaphore/Semaphore.js +11 -15
  238. package/esm/Semaphore/Semaphore.js.map +1 -1
  239. package/esm/Sink/Sink.d.ts +1 -0
  240. package/esm/Sink/Sink.d.ts.map +1 -1
  241. package/esm/Sink/Sink.js +10 -1
  242. package/esm/Sink/Sink.js.map +1 -1
  243. package/esm/Stream/Stream.d.ts +5 -14
  244. package/esm/Stream/Stream.d.ts.map +1 -1
  245. package/esm/Stream/Stream.js.map +1 -1
  246. package/esm/Stream/acquirePermit.d.ts +15 -0
  247. package/esm/Stream/acquirePermit.d.ts.map +1 -0
  248. package/esm/Stream/acquirePermit.js +15 -0
  249. package/esm/Stream/acquirePermit.js.map +1 -0
  250. package/esm/Stream/bimap.d.ts +33 -4
  251. package/esm/Stream/bimap.d.ts.map +1 -1
  252. package/esm/Stream/bimap.js +102 -11
  253. package/esm/Stream/bimap.js.map +1 -1
  254. package/esm/Stream/continueWith.d.ts +4 -3
  255. package/esm/Stream/continueWith.d.ts.map +1 -1
  256. package/esm/Stream/continueWith.js +9 -6
  257. package/esm/Stream/continueWith.js.map +1 -1
  258. package/esm/Stream/delay.d.ts +4 -0
  259. package/esm/Stream/delay.d.ts.map +1 -0
  260. package/esm/Stream/delay.js +26 -0
  261. package/esm/Stream/delay.js.map +1 -0
  262. package/esm/Stream/drain.d.ts +2 -2
  263. package/esm/Stream/drain.d.ts.map +1 -1
  264. package/esm/Stream/drain.js +6 -6
  265. package/esm/Stream/drain.js.map +1 -1
  266. package/esm/Stream/empty.d.ts.map +1 -1
  267. package/esm/Stream/empty.js +1 -2
  268. package/esm/Stream/empty.js.map +1 -1
  269. package/esm/Stream/flatMap.d.ts +7 -5
  270. package/esm/Stream/flatMap.d.ts.map +1 -1
  271. package/esm/Stream/flatMap.js +32 -19
  272. package/esm/Stream/flatMap.js.map +1 -1
  273. package/esm/Stream/flatMapConcurrently.d.ts +6 -0
  274. package/esm/Stream/flatMapConcurrently.d.ts.map +1 -0
  275. package/esm/Stream/flatMapConcurrently.js +19 -0
  276. package/esm/Stream/flatMapConcurrently.js.map +1 -0
  277. package/esm/Stream/flatMapFx.d.ts +5 -1
  278. package/esm/Stream/flatMapFx.d.ts.map +1 -1
  279. package/esm/Stream/flatMapFx.js +16 -4
  280. package/esm/Stream/flatMapFx.js.map +1 -1
  281. package/esm/Stream/foldMap.d.ts +11 -0
  282. package/esm/Stream/foldMap.d.ts.map +1 -0
  283. package/esm/Stream/foldMap.js +38 -0
  284. package/esm/Stream/foldMap.js.map +1 -0
  285. package/esm/Stream/fromArray.d.ts +2 -0
  286. package/esm/Stream/fromArray.d.ts.map +1 -0
  287. package/esm/Stream/fromArray.js +8 -0
  288. package/esm/Stream/fromArray.js.map +1 -0
  289. package/esm/Stream/fromCallback.d.ts +4 -3
  290. package/esm/Stream/fromCallback.d.ts.map +1 -1
  291. package/esm/Stream/fromCallback.js +26 -26
  292. package/esm/Stream/fromCallback.js.map +1 -1
  293. package/esm/Stream/fromFx.d.ts +23 -8
  294. package/esm/Stream/fromFx.d.ts.map +1 -1
  295. package/esm/Stream/fromFx.js +24 -14
  296. package/esm/Stream/fromFx.js.map +1 -1
  297. package/esm/Stream/hkt.d.ts +24 -1
  298. package/esm/Stream/hkt.d.ts.map +1 -1
  299. package/esm/Stream/hkt.js +41 -4
  300. package/esm/Stream/hkt.js.map +1 -1
  301. package/esm/Stream/hold.d.ts +27 -0
  302. package/esm/Stream/hold.d.ts.map +1 -0
  303. package/esm/Stream/hold.js +66 -0
  304. package/esm/Stream/hold.js.map +1 -0
  305. package/esm/Stream/index.d.ts +14 -1
  306. package/esm/Stream/index.d.ts.map +1 -1
  307. package/esm/Stream/index.js +14 -1
  308. package/esm/Stream/index.js.map +1 -1
  309. package/esm/Stream/lazy.d.ts +3 -0
  310. package/esm/Stream/lazy.d.ts.map +1 -0
  311. package/esm/Stream/lazy.js +5 -0
  312. package/esm/Stream/lazy.js.map +1 -0
  313. package/esm/Stream/merge.d.ts +18 -0
  314. package/esm/Stream/merge.d.ts.map +1 -0
  315. package/esm/Stream/merge.js +55 -0
  316. package/esm/Stream/merge.js.map +1 -0
  317. package/esm/Stream/multicast.d.ts +27 -0
  318. package/esm/Stream/multicast.d.ts.map +1 -0
  319. package/esm/Stream/multicast.js +55 -0
  320. package/esm/Stream/multicast.js.map +1 -0
  321. package/esm/Stream/orElse.d.ts +17 -0
  322. package/esm/Stream/orElse.d.ts.map +1 -0
  323. package/esm/Stream/orElse.js +77 -0
  324. package/esm/Stream/orElse.js.map +1 -0
  325. package/esm/Stream/periodic.d.ts +1 -1
  326. package/esm/Stream/periodic.d.ts.map +1 -1
  327. package/esm/Stream/periodic.js +1 -1
  328. package/esm/Stream/periodic.js.map +1 -1
  329. package/esm/Stream/provide.d.ts +8 -0
  330. package/esm/Stream/provide.d.ts.map +1 -0
  331. package/esm/Stream/provide.js +13 -0
  332. package/esm/Stream/provide.js.map +1 -0
  333. package/esm/Stream/run.d.ts +2 -2
  334. package/esm/Stream/run.d.ts.map +1 -1
  335. package/esm/Stream/run.js +2 -2
  336. package/esm/Stream/run.js.map +1 -1
  337. package/esm/Stream/scan.d.ts +17 -0
  338. package/esm/Stream/scan.d.ts.map +1 -0
  339. package/esm/Stream/scan.js +27 -0
  340. package/esm/Stream/scan.js.map +1 -0
  341. package/esm/Stream/scheduled.d.ts +12 -3
  342. package/esm/Stream/scheduled.d.ts.map +1 -1
  343. package/esm/Stream/scheduled.js +16 -4
  344. package/esm/Stream/scheduled.js.map +1 -1
  345. package/esm/Stream/setFiberRefLocally.d.ts +15 -0
  346. package/esm/Stream/setFiberRefLocally.d.ts.map +1 -0
  347. package/esm/Stream/setFiberRefLocally.js +25 -0
  348. package/esm/Stream/setFiberRefLocally.js.map +1 -0
  349. package/esm/Stream/skipRepeats.d.ts +5 -0
  350. package/esm/Stream/skipRepeats.d.ts.map +1 -0
  351. package/esm/Stream/skipRepeats.js +31 -0
  352. package/esm/Stream/skipRepeats.js.map +1 -0
  353. package/esm/Stream/switchMap.d.ts +18 -0
  354. package/esm/Stream/switchMap.d.ts.map +1 -0
  355. package/esm/Stream/switchMap.js +95 -0
  356. package/esm/Stream/switchMap.js.map +1 -0
  357. package/esm/Stream/tap.d.ts +2 -1
  358. package/esm/Stream/tap.d.ts.map +1 -1
  359. package/esm/Stream/tap.js +3 -2
  360. package/esm/Stream/tap.js.map +1 -1
  361. package/esm/Supervisor/index.d.ts +2 -0
  362. package/esm/Supervisor/index.d.ts.map +1 -1
  363. package/esm/Supervisor/index.js +2 -0
  364. package/esm/Supervisor/index.js.map +1 -1
  365. package/esm/Supervisor/inheritFiberRefs.d.ts +2 -0
  366. package/esm/Supervisor/inheritFiberRefs.d.ts.map +1 -0
  367. package/esm/Supervisor/inheritFiberRefs.js +14 -0
  368. package/esm/Supervisor/inheritFiberRefs.js.map +1 -0
  369. package/esm/Timeline/index.js.map +1 -1
  370. package/package.json +173 -37
  371. package/perf/Stream-filter-map-reduce.test.ts +103 -0
  372. package/readme.md +1 -1
  373. package/src/Cause/Cause.ts +63 -0
  374. package/src/Cause/Renderer.ts +1 -1
  375. package/src/Env/Env.ts +15 -5
  376. package/src/Fiber/fromScope.ts +19 -0
  377. package/src/FiberRef/builtins.ts +63 -11
  378. package/src/FiberRuntime/FiberRuntime.ts +35 -28
  379. package/src/Fx/Fx.test.ts +2 -2
  380. package/src/Fx/Fx.ts +11 -10
  381. package/src/Fx/join.ts +4 -4
  382. package/src/Schedule/ScheduleState.ts +3 -0
  383. package/src/Scheduler/RootScheduler.ts +7 -9
  384. package/src/Scheduler/Scheduler.ts +5 -6
  385. package/src/Scheduler/callbackScheduler.ts +1 -0
  386. package/src/Scheduler/runSchedule.ts +5 -2
  387. package/src/Scope/LocalScope.ts +8 -6
  388. package/src/Semaphore/Semaphore.ts +12 -19
  389. package/src/Sink/Sink.ts +11 -1
  390. package/src/Stream/Stream.ts +9 -15
  391. package/src/Stream/acquirePermit.ts +32 -0
  392. package/src/Stream/bimap.ts +164 -12
  393. package/src/Stream/continueWith.ts +11 -7
  394. package/src/Stream/delay.ts +43 -0
  395. package/src/Stream/drain.ts +8 -7
  396. package/src/Stream/empty.ts +1 -2
  397. package/src/Stream/flatMap.test.ts +8 -21
  398. package/src/Stream/flatMap.ts +46 -24
  399. package/src/Stream/flatMapConcurrently.test.ts +77 -0
  400. package/src/Stream/flatMapConcurrently.ts +34 -0
  401. package/src/Stream/flatMapFx.ts +37 -4
  402. package/src/Stream/foldMap.ts +88 -0
  403. package/src/Stream/fromArray.ts +8 -0
  404. package/src/Stream/fromCallback.test.ts +3 -16
  405. package/src/Stream/fromCallback.ts +48 -29
  406. package/src/Stream/fromFx.test.ts +3 -24
  407. package/src/Stream/fromFx.ts +54 -28
  408. package/src/Stream/hkt.ts +59 -10
  409. package/src/Stream/hold.test.ts +52 -0
  410. package/src/Stream/hold.ts +117 -0
  411. package/src/Stream/index.ts +14 -1
  412. package/src/Stream/lazy.ts +5 -0
  413. package/src/Stream/logging.test.ts +8 -3
  414. package/src/Stream/merge.test.ts +31 -0
  415. package/src/Stream/merge.ts +76 -0
  416. package/src/Stream/multicast.test.ts +32 -0
  417. package/src/Stream/multicast.ts +114 -0
  418. package/src/Stream/orElse.ts +107 -0
  419. package/src/Stream/periodic.ts +2 -2
  420. package/src/Stream/provide.test.ts +78 -0
  421. package/src/Stream/provide.ts +34 -0
  422. package/src/Stream/run.ts +6 -3
  423. package/src/Stream/scan.test.ts +28 -0
  424. package/src/Stream/scan.ts +46 -0
  425. package/src/Stream/scheduled.test.ts +9 -1
  426. package/src/Stream/scheduled.ts +46 -12
  427. package/src/Stream/setFiberRefLocally.ts +38 -0
  428. package/src/Stream/skipRepeats.ts +41 -0
  429. package/src/Stream/switchMap.test.ts +43 -0
  430. package/src/Stream/switchMap.ts +145 -0
  431. package/src/Stream/tap.ts +6 -3
  432. package/src/Supervisor/index.ts +2 -0
  433. package/src/Supervisor/inheritFiberRefs.ts +17 -0
  434. package/src/Timeline/index.ts +1 -0
  435. package/cjs/Effect/Effect.d.ts +0 -199
  436. package/cjs/Effect/Effect.d.ts.map +0 -1
  437. package/cjs/Effect/Effect.js +0 -66
  438. package/cjs/Effect/Effect.js.map +0 -1
  439. package/cjs/Stream/map.d.ts +0 -14
  440. package/cjs/Stream/map.d.ts.map +0 -1
  441. package/cjs/Stream/map.js +0 -30
  442. package/cjs/Stream/map.js.map +0 -1
  443. package/cjs/test.d.ts +0 -1
  444. package/cjs/test.d.ts.map +0 -1
  445. package/cjs/test.js +0 -2
  446. package/cjs/test.js.map +0 -1
  447. package/esm/Effect/Effect.d.ts +0 -199
  448. package/esm/Effect/Effect.d.ts.map +0 -1
  449. package/esm/Effect/Effect.js +0 -50
  450. package/esm/Effect/Effect.js.map +0 -1
  451. package/esm/Stream/map.d.ts +0 -14
  452. package/esm/Stream/map.d.ts.map +0 -1
  453. package/esm/Stream/map.js +0 -25
  454. package/esm/Stream/map.js.map +0 -1
  455. package/esm/test.d.ts +0 -1
  456. package/esm/test.d.ts.map +0 -1
  457. package/esm/test.js +0 -2
  458. package/esm/test.js.map +0 -1
  459. package/src/Effect/Effect.ts +0 -109
  460. package/src/Stream/map.ts +0 -35
  461. package/src/test.ts +0 -0
@@ -1,69 +1,91 @@
1
1
  import { flow, pipe } from 'hkt-ts'
2
2
 
3
3
  import { Stream } from './Stream.js'
4
- import { MapStream } from './map.js'
4
+ import { MapStream } from './bimap.js'
5
5
 
6
- import { AtomicCounter, decrement } from '@/Atomic/AtomicCounter.js'
6
+ import { AtomicCounter, decrement, increment } from '@/Atomic/AtomicCounter.js'
7
7
  import { Cause } from '@/Cause/index.js'
8
8
  import { Env } from '@/Env/Env.js'
9
9
  import { FiberContext } from '@/FiberContext/FiberContext.js'
10
10
  import { Live } from '@/FiberId/FiberId.js'
11
11
  import * as Fx from '@/Fx/index.js'
12
- import { lazy, span, unit } from '@/Fx/index.js'
12
+ import { access, lazy, unit } from '@/Fx/index.js'
13
13
  import { Scheduler } from '@/Scheduler/Scheduler.js'
14
- import { Sink } from '@/Sink/Sink.js'
14
+ import * as Sink from '@/Sink/Sink.js'
15
+ import * as Supervisor from '@/Supervisor/index.js'
15
16
 
16
17
  export function flatMap<A, R2, E2, B>(
17
18
  f: (a: A) => Stream<R2, E2, B>,
19
+ __trace?: string,
18
20
  ): <R, E>(stream: Stream<R, E, A>) => Stream<R | R2, E | E2, B> {
19
- return (stream) => FlatMapStream.make(stream, f)
21
+ return (stream) => FlatMapStream.make(stream, f, __trace)
22
+ }
23
+
24
+ export function join<R, E, R2, E2, A>(
25
+ stream: Stream<R, E, Stream<R2, E2, A>>,
26
+ __trace?: string,
27
+ ): Stream<R | R2, E | E2, A> {
28
+ return flatMap((a: Stream<R2, E2, A>) => a, __trace)(stream)
20
29
  }
21
30
 
22
31
  export class FlatMapStream<R, E, A, R2, E2, B> implements Stream<R | R2, E | E2, B> {
23
- constructor(readonly stream: Stream<R, E, A>, readonly f: (a: A) => Stream<R2, E2, B>) {}
32
+ constructor(
33
+ readonly stream: Stream<R, E, A>,
34
+ readonly f: (a: A) => Stream<R2, E2, B>,
35
+ readonly __trace?: string,
36
+ ) {}
24
37
 
25
- fork<E3>(sink: Sink<E | E2, B, E3>, scheduler: Scheduler, context: FiberContext<Live>) {
38
+ fork<E3>(sink: Sink.Sink<E | E2, B, E3>, scheduler: Scheduler, context: FiberContext<Live>) {
26
39
  const { stream, f } = this
27
40
 
28
- return pipe(
29
- Fx.getEnv<R | R2>(),
30
- Fx.flatMap((env) =>
31
- stream.fork(new FlatMapSink(sink, scheduler, context, f, env), scheduler, context),
41
+ return access((env: Env<R | R2>) =>
42
+ stream.fork(
43
+ new FlatMapSink(sink, scheduler, context, f, env, this.__trace),
44
+ scheduler,
45
+ context,
32
46
  ),
33
- span('Stream.flatMap'),
34
47
  )
35
48
  }
36
49
 
37
50
  static make<R, E, A, R2, E2, B>(
38
51
  stream: Stream<R, E, A>,
39
52
  f: (a: A) => Stream<R2, E2, B>,
53
+ __trace?: string,
40
54
  ): Stream<R | R2, E | E2, B> {
41
55
  if (stream instanceof MapStream) {
42
- return FlatMapStream.make(stream.stream, flow(stream.f, f))
56
+ return FlatMapStream.make(stream.stream, flow(stream.f, f), __trace)
43
57
  }
44
58
 
45
- return new FlatMapStream(stream, f)
59
+ return new FlatMapStream(stream, f, __trace)
46
60
  }
47
61
  }
48
62
 
49
- class FlatMapSink<R, E, A, R2, E2, B, E3> implements Sink<E | E2, A, E3> {
63
+ class FlatMapSink<R, E, A, R2, E2, B, E3> implements Sink.Sink<E | E2, A, E3> {
50
64
  protected _running = AtomicCounter()
51
65
  protected _ended = false
52
66
 
53
67
  constructor(
54
- readonly sink: Sink<E | E2, B, E3>,
68
+ readonly sink: Sink.Sink<E | E2, B, E3>,
55
69
  readonly scheduler: Scheduler,
56
70
  readonly context: FiberContext<Live>,
57
71
  readonly f: (a: A) => Stream<R2, E2, B>,
58
72
  readonly env: Env<R | R2>,
73
+ readonly __trace?: string,
59
74
  ) {}
60
75
 
61
- event = (a: A) => {
62
- return pipe(
63
- this.f(a).fork(this.innerSink(), this.scheduler, this.context.fork()),
64
- Fx.provide(this.env),
65
- )
66
- }
76
+ event = (a: A) =>
77
+ Fx.lazy(() => {
78
+ const forked = this.context.fork({
79
+ supervisor: Supervisor.and(Supervisor.inheritFiberRefs)(this.context.supervisor),
80
+ })
81
+
82
+ increment(this._running)
83
+
84
+ return pipe(
85
+ this.f(a).fork(Sink.addTrace(this.innerSink(), this.__trace), this.scheduler, forked),
86
+ Fx.provide(this.env),
87
+ )
88
+ })
67
89
 
68
90
  error = (cause: Cause<E | E2>) => {
69
91
  return lazy(() => {
@@ -82,14 +104,14 @@ class FlatMapSink<R, E, A, R2, E2, B, E3> implements Sink<E | E2, A, E3> {
82
104
  protected endIfCompleted() {
83
105
  return lazy(() => {
84
106
  if (this._ended && this._running.get() === 0) {
85
- this.sink.end
107
+ return this.sink.end
86
108
  }
87
109
 
88
110
  return unit
89
111
  })
90
112
  }
91
113
 
92
- protected innerSink(): Sink<E | E2, B, E3> {
114
+ protected innerSink(): Sink.Sink<E | E2, B, E3> {
93
115
  return {
94
116
  event: this.sink.event,
95
117
  error: this.error,
@@ -0,0 +1,77 @@
1
+ import { deepStrictEqual } from 'assert'
2
+
3
+ import { pipe } from 'hkt-ts'
4
+ import { NonNegativeInteger } from 'hkt-ts/number'
5
+
6
+ import { collectAll } from './_internal.test.js'
7
+ import { flatMapConcurrently } from './flatMapConcurrently.js'
8
+ import { fromCallback } from './fromCallback.js'
9
+ import { merge } from './merge.js'
10
+
11
+ import { testSuite } from '@/_internal/suite.js'
12
+
13
+ testSuite(import.meta.url, () => {
14
+ describe(flatMapConcurrently.name, () => {
15
+ const value = 42
16
+ const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
17
+
18
+ const stream = (level: number) =>
19
+ pipe(
20
+ fromCallback<never, number>(async ({ event, end }) => {
21
+ event(value)
22
+ event(value + 5)
23
+ event(value + 10)
24
+ end()
25
+ }),
26
+ merge(
27
+ fromCallback<never, number>(async ({ event, end }) => {
28
+ event(value + 15)
29
+ event(value + 20)
30
+ end()
31
+ }),
32
+ ),
33
+ flatMapConcurrently(
34
+ (a) =>
35
+ fromCallback<never, number>(async ({ event, end }) => {
36
+ event(a + 1)
37
+ await sleep(10)
38
+ event(a + 2)
39
+ end()
40
+ }),
41
+ NonNegativeInteger(level),
42
+ ),
43
+ )
44
+
45
+ it('it should control concurrency', async () => {
46
+ const noConcurrency = await collectAll(stream(Infinity))
47
+
48
+ deepStrictEqual(noConcurrency, [
49
+ value + 1,
50
+ value + 5 + 1,
51
+ value + 10 + 1,
52
+ value + 15 + 1,
53
+ value + 20 + 1,
54
+ value + 2,
55
+ value + 5 + 2,
56
+ value + 10 + 2,
57
+ value + 15 + 2,
58
+ value + 20 + 2,
59
+ ])
60
+
61
+ const withConcurrency = await collectAll(stream(1))
62
+
63
+ deepStrictEqual(withConcurrency, [
64
+ value + 1,
65
+ value + 2,
66
+ value + 5 + 1,
67
+ value + 5 + 2,
68
+ value + 10 + 1,
69
+ value + 10 + 2,
70
+ value + 15 + 1,
71
+ value + 15 + 2,
72
+ value + 20 + 1,
73
+ value + 20 + 2,
74
+ ])
75
+ })
76
+ })
77
+ })
@@ -0,0 +1,34 @@
1
+ import { flow, pipe } from 'hkt-ts/function'
2
+ import { NonNegativeInteger } from 'hkt-ts/number'
3
+
4
+ import { Stream } from './Stream.js'
5
+ import { acquirePermit } from './acquirePermit.js'
6
+ import { flatMap } from './flatMap.js'
7
+ import { lazy } from './lazy.js'
8
+
9
+ import { Semaphore } from '@/Semaphore/index.js'
10
+
11
+ export function flatMapConcurrently<A, R2, E2, B>(
12
+ f: (a: A) => Stream<R2, E2, B>,
13
+ concurrencyLevel: NonNegativeInteger,
14
+ __trace?: string,
15
+ ) {
16
+ return <R, E>(stream: Stream<R, E, A>) =>
17
+ lazy(() => {
18
+ const semaphore = new Semaphore(concurrencyLevel)
19
+
20
+ return pipe(stream, flatMap(flow(f, acquirePermit(semaphore)), __trace))
21
+ })
22
+ }
23
+
24
+ export function mergeConcurrently(concurrencyLevel: NonNegativeInteger, __trace?: string) {
25
+ return <R, E, R2, E2, A>(stream: Stream<R, E, Stream<R2, E2, A>>) =>
26
+ pipe(
27
+ stream,
28
+ flatMapConcurrently((a) => a, concurrencyLevel, __trace),
29
+ )
30
+ }
31
+
32
+ export function concatMap<A, R2, E2, B>(f: (a: A) => Stream<R2, E2, B>, __trace?: string) {
33
+ return flow(flatMapConcurrently(f, NonNegativeInteger(1), __trace))
34
+ }
@@ -1,12 +1,45 @@
1
- import { flow, pipe } from 'hkt-ts/function'
1
+ import { pipe } from 'hkt-ts/function'
2
+ import { NonNegativeInteger } from 'hkt-ts/number'
2
3
 
3
4
  import { Stream } from './Stream.js'
4
5
  import { flatMap } from './flatMap.js'
5
- import { makeFromFx } from './fromFx.js'
6
+ import { flatMapConcurrently } from './flatMapConcurrently.js'
7
+ import { fromFx } from './fromFx.js'
6
8
 
7
9
  import { Fx } from '@/Fx/Fx.js'
8
10
 
9
- export function flatMapFx<A, R2, E2, B>(f: (a: A) => Fx<R2, E2, B>, span = 'Stream.flatMapFx') {
11
+ export function flatMapFx<A, R2, E2, B>(f: (a: A) => Fx<R2, E2, B>, __trace?: string) {
10
12
  return <R, E>(stream: Stream<R, E, A>): Stream<R | R2, E | E2, B> =>
11
- pipe(stream, flatMap(flow(f, makeFromFx(span))))
13
+ pipe(
14
+ stream,
15
+ flatMap((a) => fromFx(f(a), __trace), __trace),
16
+ )
17
+ }
18
+
19
+ export function joinFx<R, E, A>(stream: Stream<R, E, Fx<R, E, A>>, __trace?: string) {
20
+ return pipe(
21
+ stream,
22
+ flatMapFx((x) => x, __trace),
23
+ )
24
+ }
25
+
26
+ export function flatMapFxConcurrently<A, R2, E2, B>(
27
+ f: (a: A) => Fx<R2, E2, B>,
28
+ concurrencyLevel: NonNegativeInteger,
29
+ __trace?: string,
30
+ ) {
31
+ return <R, E>(stream: Stream<R, E, A>): Stream<R | R2, E | E2, B> =>
32
+ pipe(
33
+ stream,
34
+ flatMapConcurrently((a) => fromFx(f(a), __trace), concurrencyLevel, __trace),
35
+ )
36
+ }
37
+
38
+ export function mergeFxConcurrently(concurrencyLevel: NonNegativeInteger, __trace?: string) {
39
+ return <R, E, R2, E2, A>(stream: Stream<R, E, Fx<R2, E2, A>>) => {
40
+ return pipe(
41
+ stream,
42
+ flatMapFxConcurrently((x) => x, concurrencyLevel, __trace),
43
+ )
44
+ }
12
45
  }
@@ -0,0 +1,88 @@
1
+ import { Maybe, flow, pipe } from 'hkt-ts'
2
+ import * as Endo from 'hkt-ts/Endomorphism'
3
+ import { Identity } from 'hkt-ts/Typeclass/Identity'
4
+ import * as B from 'hkt-ts/boolean'
5
+
6
+ import { Stream } from './Stream.js'
7
+ import { FilterMapStream, MapStream } from './bimap.js'
8
+ import { observe } from './drain.js'
9
+ import { FromFxStream } from './fromFx.js'
10
+
11
+ import * as Fx from '@/Fx/index.js'
12
+ import { Scheduler } from '@/Scheduler/Scheduler.js'
13
+
14
+ export const filterFoldMap = <A>(I: Identity<A>) => {
15
+ const foldMap_ =
16
+ <B>(f: (b: B) => Maybe.Maybe<A>, __trace?: string) =>
17
+ <R, E>(stream: Stream<R, E, B>): Fx.Fx<R | Scheduler, E, A> => {
18
+ if (stream instanceof FromFxStream) {
19
+ return pipe(
20
+ stream.fx,
21
+ Fx.map(
22
+ flow(
23
+ f,
24
+ Maybe.match(
25
+ () => I.id,
26
+ (a) => I.concat(I.id, a),
27
+ ),
28
+ ),
29
+ ),
30
+ )
31
+ }
32
+
33
+ if (stream instanceof MapStream) {
34
+ return foldMap_(flow(stream.f, f), __trace)(stream.stream)
35
+ }
36
+
37
+ if (stream instanceof FilterMapStream) {
38
+ return foldMap_(flow(stream.f, Maybe.flatMap(f)), __trace)(stream.stream)
39
+ }
40
+
41
+ return filterFoldMapStream(I, f, stream, __trace)
42
+ }
43
+
44
+ return foldMap_
45
+ }
46
+
47
+ export const foldMap =
48
+ <A>(I: Identity<A>) =>
49
+ <B>(f: (b: B) => A) =>
50
+ filterFoldMap(I)(flow(f, Maybe.Just))
51
+
52
+ const filterFoldMapStream = <A, B, R, E>(
53
+ I: Identity<A>,
54
+ f: (b: B) => Maybe.Maybe<A>,
55
+ stream: Stream<R, E, B>,
56
+ __trace?: string,
57
+ ) =>
58
+ Fx.lazy(() => {
59
+ let acc = I.id
60
+
61
+ return pipe(
62
+ stream,
63
+ observe((b) =>
64
+ Fx.fromLazy(() => {
65
+ const maybe = f(b)
66
+
67
+ if (Maybe.isJust(maybe)) {
68
+ acc = I.concat(acc, maybe.value)
69
+ }
70
+ }),
71
+ ),
72
+ Fx.flatMap(Fx.join),
73
+ Fx.map(() => acc, __trace),
74
+ )
75
+ })
76
+
77
+ export const reduce = <A, B>(
78
+ f: (a: A, b: B) => A,
79
+ seed: A,
80
+ ): (<R, E>(stream: Stream<R, E, B>) => Fx.Fx<Scheduler | R, E, A>) => {
81
+ return flow(
82
+ foldMap(Endo.makeIdentity<A>())((a: B) => (b: A) => f(b, a)),
83
+ Fx.flap(seed),
84
+ )
85
+ }
86
+
87
+ export const every = foldMap(B.All)
88
+ export const some = foldMap(B.Any)
@@ -0,0 +1,8 @@
1
+ import { fromCallback } from './fromCallback.js'
2
+
3
+ export function fromArray<A>(array: ReadonlyArray<A>) {
4
+ return fromCallback<never, A>(async ({ event, end }) => {
5
+ await Promise.all(array.map(event))
6
+ await end()
7
+ })
8
+ }
@@ -1,13 +1,8 @@
1
1
  import { deepStrictEqual } from 'assert'
2
2
 
3
- import { pipe } from 'hkt-ts'
4
-
5
- import { collect } from './drain.js'
3
+ import { collectAll } from './_internal.test.js'
6
4
  import { fromCallback } from './fromCallback.js'
7
5
 
8
- import * as Fx from '@/Fx/index.js'
9
- import { RootScheduler } from '@/Scheduler/RootScheduler.js'
10
- import { Scheduler } from '@/Scheduler/Scheduler.js'
11
6
  import { testSuite } from '@/_internal/suite.js'
12
7
 
13
8
  testSuite(import.meta.url, () => {
@@ -20,16 +15,8 @@ testSuite(import.meta.url, () => {
20
15
  await end()
21
16
  })
22
17
 
23
- it('should be collectable', async () => {
24
- await pipe(
25
- Fx.Fx(function* () {
26
- const events: readonly number[] = yield* collect(stream)
27
-
28
- deepStrictEqual(events, [value, value + 1, value + 2])
29
- }),
30
- Fx.provideService(Scheduler, RootScheduler()),
31
- Fx.runMain,
32
- )
18
+ it('is collectable', async () => {
19
+ deepStrictEqual(await collectAll(stream), [value, value + 1, value + 2])
33
20
  })
34
21
  })
35
22
  })
@@ -1,19 +1,18 @@
1
1
  import { flow, pipe } from 'hkt-ts'
2
+ import { Left, Right } from 'hkt-ts/Either'
2
3
 
3
4
  import { Stream } from './Stream.js'
4
5
 
5
6
  import { Cause } from '@/Cause/index.js'
6
- import { Fiber, Synthetic } from '@/Fiber/Fiber.js'
7
+ import { Fiber } from '@/Fiber/Fiber.js'
8
+ import { fromScope } from '@/Fiber/fromScope.js'
7
9
  import { FiberContext } from '@/FiberContext/FiberContext.js'
8
10
  import { FiberId } from '@/FiberId/FiberId.js'
9
- import * as FiberRefs from '@/FiberRefs/FiberRefs.js'
10
11
  import { Finalizer } from '@/Finalizer/Finalizer.js'
11
12
  import * as Fx from '@/Fx/index.js'
12
13
  import { Runtime } from '@/Runtime/Runtime.js'
13
14
  import { Scheduler } from '@/Scheduler/Scheduler.js'
14
- import { closeOrWait, wait } from '@/Scope/Closeable.js'
15
- import { Sink } from '@/Sink/Sink.js'
16
- import { Exit } from '@/index.js'
15
+ import { Sink, addTrace } from '@/Sink/Sink.js'
17
16
 
18
17
  export interface CallbackSink<E, A> {
19
18
  readonly event: (a: A) => Promise<any>
@@ -21,45 +20,65 @@ export interface CallbackSink<E, A> {
21
20
  readonly end: () => Promise<any>
22
21
  }
23
22
 
24
- export function fromCallback<E, A>(
25
- f: <E2>(sink: CallbackSink<E | E2, A>) => Finalizer | void | Promise<Finalizer | void>,
23
+ export function fromCallback<E = never, A = unknown>(
24
+ f: (sink: CallbackSink<E, A>) => Finalizer | void | Promise<Finalizer | void>,
25
+ __trace?: string,
26
26
  ): Stream<never, E, A> {
27
- return new FromCallback<E, A>(f)
27
+ return new FromCallback<E, A>(f, __trace)
28
28
  }
29
29
 
30
30
  export class FromCallback<E, A> implements Stream<never, E, A> {
31
31
  constructor(
32
- readonly f: <E2>(sink: CallbackSink<E | E2, A>) => Finalizer | void | Promise<Finalizer | void>,
32
+ readonly f: (sink: CallbackSink<E, A>) => Finalizer | void | Promise<Finalizer | void>,
33
+ readonly __trace?: string,
33
34
  ) {}
34
35
 
35
36
  fork = <E2>(
36
37
  sink: Sink<E, A, E2>,
37
38
  _: Scheduler,
38
39
  context: FiberContext<FiberId.Live>,
39
- ): Fx.RIO<never, Fiber<E2, any>> =>
40
- Fx.fromPromise(async () => {
40
+ ): Fx.RIO<never, Fiber<E2, any>> => {
41
+ return Fx.lazy(() => {
42
+ const { f, __trace } = this
43
+
41
44
  const runtime = Runtime(context)
42
- const cbSink = {
43
- event: flow(sink.event, runtime.run),
44
- error: flow(sink.error, runtime.run),
45
- end: () => pipe(sink.end, runtime.run),
45
+ const tracedSink = addTrace(sink, __trace)
46
+ const cbSink: CallbackSink<E, A> = {
47
+ event: flow(tracedSink.event, runtime.run),
48
+ error: (cause) =>
49
+ pipe(
50
+ cause,
51
+ tracedSink.error,
52
+ Fx.tap(() => context.scope.close(Left(cause))),
53
+ runtime.run,
54
+ ),
55
+ end: () =>
56
+ pipe(
57
+ tracedSink.end,
58
+ Fx.tap(() => context.scope.close(Right(undefined))),
59
+ runtime.run,
60
+ ),
46
61
  }
47
- const finalizer = await this.f(cbSink)
48
62
 
49
- if (finalizer) {
50
- context.scope.ensuring(finalizer)
51
- }
63
+ const synthetic = fromScope(
64
+ new FiberId.Synthetic([context.id]),
65
+ context.fiberRefs,
66
+ context.scope,
67
+ )
52
68
 
53
- const synthetic = Synthetic({
54
- id: new FiberId.Synthetic([context.id]),
55
- exit: wait(context.scope),
56
- inheritFiberRefs: pipe(
57
- Fx.getFiberRefs,
58
- Fx.flatMap((refs) => Fx.fromLazy(() => FiberRefs.join(refs, context.fiberRefs))),
69
+ return pipe(
70
+ Fx.fromPromise(async () => await f(cbSink)),
71
+ Fx.tap(
72
+ (finalizer) =>
73
+ (finalizer &&
74
+ (context.scope.state.tag === 'Open'
75
+ ? Fx.fromLazy(() => context.scope.ensuring(finalizer))
76
+ : finalizer(context.scope.state.exit))) ??
77
+ Fx.unit,
59
78
  ),
60
- interruptAs: (id) => closeOrWait(context.scope)(Exit.interrupt(id)),
61
- })
62
-
63
- return synthetic
79
+ Fx.fork,
80
+ Fx.map(() => synthetic),
81
+ )
64
82
  })
83
+ }
65
84
  }
@@ -1,38 +1,17 @@
1
1
  import { deepStrictEqual } from 'assert'
2
2
 
3
- import { pipe } from 'hkt-ts'
4
-
5
- import { collect, observe } from './drain.js'
3
+ import { collectAll } from './_internal.test.js'
6
4
  import { fromFx } from './fromFx.js'
7
5
 
8
6
  import * as Fx from '@/Fx/index.js'
9
- import { RootScheduler } from '@/Scheduler/RootScheduler.js'
10
- import { Scheduler } from '@/Scheduler/Scheduler.js'
11
7
 
12
8
  describe(new URL(import.meta.url).pathname, () => {
13
9
  describe(fromFx.name, () => {
14
10
  const value = Math.random()
15
11
  const stream = fromFx(Fx.success(value))
16
12
 
17
- it('should create a Stream', () =>
18
- pipe(
19
- stream,
20
- observe((n) => Fx.fromLazy(() => deepStrictEqual(n, value))),
21
- Fx.flatMap(Fx.join),
22
- Fx.provideService(Scheduler, RootScheduler()),
23
- Fx.runMain,
24
- ))
25
-
26
- it('should be collectable', async () => {
27
- await pipe(
28
- Fx.Fx(function* () {
29
- const events: readonly number[] = yield* collect(stream)
30
-
31
- deepStrictEqual(events, [value])
32
- }),
33
- Fx.provideService(Scheduler, RootScheduler()),
34
- Fx.runMain,
35
- )
13
+ it('is collectable', async () => {
14
+ deepStrictEqual(await collectAll(stream), [value])
36
15
  })
37
16
  })
38
17
  })
@@ -1,45 +1,71 @@
1
1
  import { flow, pipe } from 'hkt-ts'
2
+ import { Either } from 'hkt-ts/Either'
2
3
 
3
4
  import { Stream } from './Stream.js'
4
5
 
6
+ import { Cause } from '@/Cause/Cause.js'
5
7
  import { Env } from '@/Env/Env.js'
8
+ import * as Exit from '@/Exit/Exit.js'
9
+ import { FiberContext } from '@/FiberContext/FiberContext.js'
10
+ import { FiberId } from '@/FiberId/index.js'
6
11
  import * as Fx from '@/Fx/Fx.js'
7
- import { span } from '@/index.js'
12
+ import { Scheduler } from '@/Scheduler/Scheduler.js'
13
+ import { Sink } from '@/Sink/Sink.js'
8
14
 
9
15
  /**
10
16
  * Constructs a Stream from an Fx that runs within a LogSpan enabling
11
17
  */
12
- export function makeFromFx(logSpan: string) {
13
- return <R, E, A>(fx: Fx.Fx<R, E, A>, __trace?: string): Stream<R, E, A> => {
14
- return Stream((sink, scheduler, context) =>
15
- Fx.asksEnv(
16
- (env: Env<R>) =>
17
- scheduler.asap(
18
- pipe(
19
- fx,
20
- Fx.matchCause(
21
- sink.error,
22
- flow(
23
- sink.event,
24
- Fx.flatMap(() => sink.end),
25
- ),
18
+ export function fromFx<R, E, A>(fx: Fx.Fx<R, E, A>, __trace?: string): Stream<R, E, A> {
19
+ return new FromFxStream(fx, __trace)
20
+ }
21
+
22
+ export class FromFxStream<R, E, A> implements Stream<R, E, A> {
23
+ constructor(readonly fx: Fx.Fx<R, E, A>, readonly __trace?: string) {}
24
+
25
+ fork<E2>(sink: Sink<E, A, E2>, scheduler: Scheduler, context: FiberContext<FiberId.Live>) {
26
+ return Fx.asksEnv(
27
+ (env: Env<R>) =>
28
+ scheduler.asap(
29
+ pipe(
30
+ this.fx,
31
+ Fx.matchCause(
32
+ sink.error,
33
+ flow(
34
+ sink.event,
35
+ Fx.flatMap(() => sink.end),
26
36
  ),
37
+ this.__trace,
27
38
  ),
28
- env,
29
- context,
30
- span(logSpan),
31
39
  ),
32
- __trace,
33
- ),
40
+ env,
41
+ context,
42
+ ),
43
+ this.__trace,
34
44
  )
35
45
  }
36
46
  }
37
47
 
38
- export const fromFx = makeFromFx('Stream.fromFx')
39
- export const now = flow(Fx.now, makeFromFx('Stream.now'))
40
- export const fromCause = flow(Fx.fromCause, makeFromFx(`Stream.fromCause`))
41
- export const fromExit = flow(Fx.fromExit, makeFromFx(`Stream.fromExit`))
42
- export const fromPromise = flow(Fx.fromPromise, makeFromFx(`Stream.fromPromise`))
43
- export const fromLazy = flow(Fx.fromLazy, makeFromFx(`Stream.fromLazy`))
44
- export const fromEither = flow(Fx.fromEither, makeFromFx(`Stream.fromEither`))
45
- export const never = makeFromFx(`Stream.never`)(Fx.never)
48
+ export const now = <A>(value: A, __trace?: string) => fromFx(Fx.now(value), __trace)
49
+
50
+ export const fromCause = <E>(cause: Cause<E>, __trace?: string) =>
51
+ fromFx(Fx.fromCause(cause), __trace)
52
+
53
+ export const fromExit = <E, A>(exit: Exit.Exit<E, A>, __trace?: string) =>
54
+ fromFx(Fx.fromExit(exit), __trace)
55
+
56
+ export const interrupt = (id: FiberId, __trace?: string) => fromExit(Exit.interrupt(id), __trace)
57
+
58
+ export const unexpected = (error: unknown, __trace?: string) =>
59
+ fromExit(Exit.unexpected(error), __trace)
60
+
61
+ export const expected = <E>(error: E, __trace?: string) => fromExit(Exit.expected(error), __trace)
62
+
63
+ export const fromPromise = <A>(promise: () => Promise<A>, __trace?: string) =>
64
+ fromFx(Fx.fromPromise(promise), __trace)
65
+
66
+ export const fromLazy = <A>(lazy: () => A, __trace?: string) => fromFx(Fx.fromLazy(lazy), __trace)
67
+
68
+ export const fromEither = <E, A>(either: Either<E, A>, __trace?: string) =>
69
+ fromFx(Fx.fromEither(either), __trace)
70
+
71
+ export const never = fromFx(Fx.never, 'never')