@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
@@ -4,7 +4,7 @@ import { NonNegativeInteger } from 'hkt-ts/number'
4
4
  import { AtomicCounter, decrement, increment } from '@/Atomic/AtomicCounter.js'
5
5
  import { MutableFutureQueue } from '@/Future/MutableFutureQueue.js'
6
6
  import { wait } from '@/Future/wait.js'
7
- import { Fx, Of, flatMap, fromLazy, tap, unit } from '@/Fx/Fx.js'
7
+ import * as Fx from '@/Fx/Fx.js'
8
8
  import { fiberScoped, managed, scoped } from '@/Fx/scoped.js'
9
9
 
10
10
  export class Semaphore {
@@ -22,10 +22,10 @@ export class Semaphore {
22
22
  return this.running.get()
23
23
  }
24
24
 
25
- readonly prepare = fromLazy(() => {
25
+ readonly prepare = Fx.fromLazy(() => {
26
26
  if (this.available > 0) {
27
27
  return new Acquisition(
28
- fromLazy(() => {
28
+ Fx.fromLazy(() => {
29
29
  increment(this.running)
30
30
  }),
31
31
  this.release,
@@ -39,11 +39,7 @@ export class Semaphore {
39
39
  const acquisition = new Acquisition(
40
40
  pipe(
41
41
  wait(future),
42
- tap(() =>
43
- fromLazy(() => {
44
- increment(that.running)
45
- }),
46
- ),
42
+ Fx.tapLazy(() => increment(that.running)),
47
43
  ),
48
44
  this.release,
49
45
  )
@@ -51,17 +47,14 @@ export class Semaphore {
51
47
  return acquisition
52
48
  })
53
49
 
54
- protected release = fromLazy(() => {
50
+ protected release = Fx.fromLazy(() => {
55
51
  decrement(this.running)
56
-
57
- if (this.waiting.size() > 0) {
58
- this.waiting.next(unit)
59
- }
52
+ this.waiting.next(Fx.unit)
60
53
  })
61
54
  }
62
55
 
63
56
  export class Acquisition {
64
- constructor(readonly acquire: Of<void>, readonly release: Of<void>) {}
57
+ constructor(readonly acquire: Fx.Of<void>, readonly release: Fx.Of<void>) {}
65
58
  }
66
59
 
67
60
  /**
@@ -80,7 +73,7 @@ export class Lock extends Semaphore {
80
73
  export function acquirePermit(semaphore: Semaphore) {
81
74
  return pipe(
82
75
  semaphore.prepare,
83
- flatMap(({ acquire, release }) => managed(acquire, constant(release))),
76
+ Fx.flatMap(({ acquire, release }) => managed(acquire, constant(release))),
84
77
  )
85
78
  }
86
79
 
@@ -88,10 +81,10 @@ export function acquirePermit(semaphore: Semaphore) {
88
81
  * Acquire a permit from a given semaphore, run an Fx, and then release the permit.
89
82
  */
90
83
  export function acquire(semaphore: Semaphore) {
91
- return <R, E, A>(fx: Fx<R, E, A>) =>
84
+ return <R, E, A>(fx: Fx.Fx<R, E, A>) =>
92
85
  pipe(
93
86
  acquirePermit(semaphore),
94
- flatMap(() => fx),
87
+ Fx.flatMap(() => fx),
95
88
  scoped,
96
89
  )
97
90
  }
@@ -100,10 +93,10 @@ export function acquire(semaphore: Semaphore) {
100
93
  * Acquire a permit from a given semaphore, run an Fx, and then release the permit.
101
94
  */
102
95
  export function acquireFiber(semaphore: Semaphore) {
103
- return <R, E, A>(fx: Fx<R, E, A>) =>
96
+ return <R, E, A>(fx: Fx.Fx<R, E, A>) =>
104
97
  pipe(
105
98
  acquirePermit(semaphore),
106
- flatMap(() => fx),
99
+ Fx.flatMap(() => fx),
107
100
  fiberScoped,
108
101
  )
109
102
  }
package/src/Sink/Sink.ts CHANGED
@@ -2,7 +2,7 @@ import { flow, pipe } from 'hkt-ts'
2
2
  import { Left, Right } from 'hkt-ts/Either'
3
3
 
4
4
  import { Cause } from '@/Cause/Cause.js'
5
- import { Fx, IO, access, flatMap, fromLazy, provide, unit } from '@/Fx/Fx.js'
5
+ import { Fx, IO, access, addCustomTrace, flatMap, fromLazy, provide, unit } from '@/Fx/Fx.js'
6
6
  import { Closeable } from '@/Scope/Closeable.js'
7
7
 
8
8
  export interface Sink<in E, in A, out E2 = never> {
@@ -77,3 +77,13 @@ export function makeDrain<
77
77
  }),
78
78
  )
79
79
  }
80
+
81
+ export function addTrace<E, A, E2>(sink: Sink<E, A, E2>, trace?: string): Sink<E, A, E2> {
82
+ if (trace === undefined) return sink
83
+
84
+ return {
85
+ event: flow(sink.event, addCustomTrace(trace)),
86
+ error: flow(sink.error, addCustomTrace(trace)),
87
+ end: pipe(sink.end, addCustomTrace(trace)),
88
+ }
89
+ }
@@ -7,19 +7,13 @@ import { Sink } from '@/Sink/Sink.js'
7
7
 
8
8
  /**
9
9
  * TODOS:
10
- * - Scan
11
10
  * - Loop
12
11
  * - zipItems
13
12
  * - withItems
14
- * - switchLatest
15
- * - concatMap
16
- * - mergeConcurrently
17
- * - merge/mergeArray
18
13
  * - combine/combineArray
19
14
  * - zip/zipArray
20
15
  * - sample
21
16
  * - snapshot
22
- * - skipRepeats
23
17
  * - slice/take/skip
24
18
  * - takeWhile/skipWhile
25
19
  * - takeUntil/skipUntil
@@ -27,27 +21,27 @@ import { Sink } from '@/Sink/Sink.js'
27
21
  * - since
28
22
  * - during
29
23
  * - until
30
- * - delay
31
24
  * - throttle
32
25
  * - debounce
33
- * - orElse
34
- * - multicast
35
- * - hold
36
- * - reduce
37
- * - run
38
26
  * - Fusion/Commutation
39
27
  * - Unique Identification for streams to add to tracing
40
28
  * - How to build a dynamic stream graph?
41
29
  */
42
30
 
43
- export interface Stream<R = never, E = never, A = unknown> {
44
- readonly fork: <E2 = never>(
31
+ export interface Stream<out R = never, out E = never, out A = unknown> {
32
+ fork<E2 = never>(
45
33
  sink: Sink<E, A, E2>,
46
34
  scheduler: Scheduler,
47
35
  context: FiberContext<FiberId.Live>,
48
- ) => Fx.RIO<R, Fiber<E2, any>>
36
+ ): Fx.RIO<R, Fiber<E2, any>>
49
37
  }
50
38
 
39
+ /* eslint-disable @typescript-eslint/no-unused-vars */
40
+ export type ResourcesOf<T> = T extends Stream<infer R, infer _, infer __> ? R : never
41
+ export type ErrorsOf<T> = T extends Stream<infer _, infer E, infer __> ? E : never
42
+ export type OutputOf<T> = T extends Stream<infer _, infer __, infer A> ? A : never
43
+ /* eslint-enable @typescript-eslint/no-unused-vars */
44
+
51
45
  export interface RIO<R, A> extends Stream<R, never, A> {}
52
46
  export interface IO<E, A> extends Stream<never, E, A> {}
53
47
  export interface Of<A> extends Stream<never, never, A> {}
@@ -0,0 +1,32 @@
1
+ import { pipe } from 'hkt-ts/function'
2
+
3
+ import { Stream } from './Stream.js'
4
+
5
+ import { FiberContext } from '@/FiberContext/FiberContext.js'
6
+ import { Live } from '@/FiberId/FiberId.js'
7
+ import * as Fx from '@/Fx/Fx.js'
8
+ import { Scheduler } from '@/Scheduler/index.js'
9
+ import * as Semaphore from '@/Semaphore/index.js'
10
+ import { Sink } from '@/Sink/Sink.js'
11
+
12
+ export function acquirePermit(semaphore: Semaphore.Semaphore) {
13
+ return <R, E, A>(stream: Stream<R, E, A>): Stream<R, E, A> =>
14
+ new AcquirePermitStream(stream, semaphore)
15
+ }
16
+
17
+ export class AcquirePermitStream<R, E, A> implements Stream<R, E, A> {
18
+ constructor(readonly stream: Stream<R, E, A>, readonly semaphore: Semaphore.Semaphore) {}
19
+
20
+ fork = <E2>(sink: Sink<E, A, E2>, scheduler: Scheduler, context: FiberContext<Live>) =>
21
+ pipe(
22
+ this.semaphore.prepare,
23
+ Fx.flatMap(({ acquire, release }) =>
24
+ pipe(
25
+ acquire,
26
+ Fx.uninterruptable,
27
+ Fx.tapLazy(() => context.scope.ensuring(() => release)),
28
+ Fx.flatMap(() => this.stream.fork(sink, scheduler, context)),
29
+ ),
30
+ ),
31
+ )
32
+ }
@@ -1,26 +1,33 @@
1
- import { flow } from 'hkt-ts/function'
1
+ import { Maybe } from 'hkt-ts'
2
+ import { flow, pipe } from 'hkt-ts/function'
2
3
 
3
4
  import { Stream } from './Stream.js'
4
- import { MapStream } from './map.js'
5
5
 
6
6
  import * as Cause from '@/Cause/index.js'
7
7
  import { FiberContext } from '@/FiberContext/FiberContext.js'
8
8
  import { Live } from '@/FiberId/FiberId.js'
9
+ import { unit } from '@/Fx/Fx.js'
9
10
  import { Scheduler } from '@/Scheduler/Scheduler.js'
10
- import { Sink } from '@/Sink/Sink.js'
11
+ import { Sink, addTrace } from '@/Sink/Sink.js'
11
12
 
12
13
  export function bimap<A, B, C, D>(
13
14
  f: (a: A) => B,
14
15
  g: (c: C) => D,
16
+ __trace?: string,
15
17
  ): <R>(stream: Stream<R, A, C>) => Stream<R, B, D> {
16
- return (stream) => BimapStream.make(stream, f, g)
18
+ return (stream) => BimapStream.make(stream, f, g, __trace)
17
19
  }
18
20
 
19
21
  export class BimapStream<R, A, B, C, D> implements Stream<R, B, D> {
20
- constructor(readonly stream: Stream<R, A, C>, readonly f: (a: A) => B, readonly g: (c: C) => D) {}
22
+ constructor(
23
+ readonly stream: Stream<R, A, C>,
24
+ readonly f: (a: A) => B,
25
+ readonly g: (c: C) => D,
26
+ readonly __trace?: string,
27
+ ) {}
21
28
 
22
- fork = <E2>(sink: Sink<B, D, E2>, scheduler: Scheduler, context: FiberContext<Live>) => {
23
- return this.stream.fork<E2>(
29
+ fork = <E>(sink: Sink<B, D, E>, scheduler: Scheduler, context: FiberContext<Live>) => {
30
+ return this.stream.fork<E>(
24
31
  new BimapSink(sink, scheduler, context, this.f, this.g),
25
32
  scheduler,
26
33
  context,
@@ -31,16 +38,17 @@ export class BimapStream<R, A, B, C, D> implements Stream<R, B, D> {
31
38
  stream: Stream<R, A, C>,
32
39
  f: (a: A) => B,
33
40
  g: (c: C) => D,
41
+ __trace?: string,
34
42
  ): Stream<R, B, D> {
35
43
  if (stream instanceof MapStream) {
36
- return BimapStream.make(stream.stream, f, flow(stream.f, g))
44
+ return BimapStream.make(stream.stream, f, flow(stream.f, g), __trace)
37
45
  }
38
46
 
39
47
  if (stream instanceof BimapStream) {
40
- return BimapStream.make(stream.stream, flow(stream.f, f), flow(stream.g, g))
48
+ return BimapStream.make(stream.stream, flow(stream.f, f), flow(stream.g, g), __trace)
41
49
  }
42
50
 
43
- return new BimapStream(stream, f, g)
51
+ return new BimapStream(stream, f, g, __trace)
44
52
  }
45
53
  }
46
54
 
@@ -53,7 +61,151 @@ class BimapSink<A, B, C, D, E> implements Sink<A, C, E> {
53
61
  readonly g: (c: C) => D,
54
62
  ) {}
55
63
 
56
- event = (c: C) => this.sink.event(this.g(c))
57
- error = (cause: Cause.Cause<A>) => this.sink.error(Cause.map(this.f)(cause))
64
+ event = flow(this.g, this.sink.event)
65
+ error = flow(Cause.map(this.f), this.sink.error)
58
66
  end = this.sink.end
59
67
  }
68
+
69
+ export function map<A, B>(
70
+ f: (a: A) => B,
71
+ __trace?: string,
72
+ ): <R, E>(stream: Stream<R, E, A>) => Stream<R, E, B> {
73
+ return (stream) => MapStream.make(stream, f, __trace)
74
+ }
75
+
76
+ export class MapStream<R, E, A, B> implements Stream<R, E, B> {
77
+ constructor(
78
+ readonly stream: Stream<R, E, A>,
79
+ readonly f: (a: A) => B,
80
+ readonly __trace?: string,
81
+ ) {}
82
+
83
+ fork<E2>(sink: Sink<E, B, E2>, scheduler: Scheduler, context: FiberContext<Live>) {
84
+ return this.stream.fork(
85
+ addTrace(
86
+ {
87
+ ...sink,
88
+ event: flow(this.f, sink.event),
89
+ },
90
+ this.__trace,
91
+ ),
92
+ scheduler,
93
+ context,
94
+ )
95
+ }
96
+
97
+ static make<R, E, A, B>(
98
+ stream: Stream<R, E, A>,
99
+ f: (a: A) => B,
100
+ __trace?: string,
101
+ ): Stream<R, E, B> {
102
+ if (stream instanceof MapStream) {
103
+ return MapStream.make(stream.stream, flow(stream.f, f), __trace)
104
+ }
105
+
106
+ if (stream instanceof MapLeftStream) {
107
+ return BimapStream.make(stream.stream, stream.f, f, __trace)
108
+ }
109
+
110
+ if (stream instanceof FilterMapStream) {
111
+ return FilterMapStream.make(stream.stream, flow(stream.f, Maybe.map(f)), __trace)
112
+ }
113
+
114
+ return new MapStream(stream, f, __trace)
115
+ }
116
+ }
117
+
118
+ export function mapLeft<E1, E2>(
119
+ f: (error: E1) => E2,
120
+ __trace?: string,
121
+ ): <R, A>(stream: Stream<R, E1, A>) => Stream<R, E2, A> {
122
+ return (stream) => MapLeftStream.make(stream, f, __trace)
123
+ }
124
+
125
+ export class MapLeftStream<R, E1, A, E2> implements Stream<R, E2, A> {
126
+ constructor(
127
+ readonly stream: Stream<R, E1, A>,
128
+ readonly f: (error: E1) => E2,
129
+ readonly __trace?: string,
130
+ ) {}
131
+
132
+ fork<E3>(sink: Sink<E2, A, E3>, scheduler: Scheduler, context: FiberContext<Live>) {
133
+ return this.stream.fork(
134
+ addTrace(
135
+ {
136
+ ...sink,
137
+ error: flow(Cause.map(this.f), sink.error),
138
+ },
139
+ this.__trace,
140
+ ),
141
+ scheduler,
142
+ context,
143
+ )
144
+ }
145
+
146
+ static make<R, E1, A, E2>(
147
+ stream: Stream<R, E1, A>,
148
+ f: (e: E1) => E2,
149
+ __trace?: string,
150
+ ): Stream<R, E2, A> {
151
+ if (stream instanceof MapLeftStream) {
152
+ return MapLeftStream.make(stream.stream, flow(stream.f, f), __trace)
153
+ }
154
+
155
+ if (stream instanceof MapStream) {
156
+ return BimapStream.make(stream.stream, f, stream.f, __trace)
157
+ }
158
+
159
+ return new MapLeftStream(stream, f, __trace)
160
+ }
161
+ }
162
+
163
+ export function filterMap<A, B>(
164
+ f: (a: A) => Maybe.Maybe<B>,
165
+ __trace?: string,
166
+ ): <R, E>(stream: Stream<R, E, A>) => Stream<R, E, B> {
167
+ return (stream) => FilterMapStream.make(stream, f, __trace)
168
+ }
169
+
170
+ export class FilterMapStream<R, E, A, B> implements Stream<R, E, B> {
171
+ constructor(
172
+ readonly stream: Stream<R, E, A>,
173
+ readonly f: (a: A) => Maybe.Maybe<B>,
174
+ readonly __trace?: string,
175
+ ) {}
176
+
177
+ fork<E2>(sink: Sink<E, B, E2>, scheduler: Scheduler, context: FiberContext<Live>) {
178
+ return this.stream.fork(
179
+ addTrace(
180
+ {
181
+ ...sink,
182
+ event: (a) =>
183
+ pipe(
184
+ a,
185
+ this.f,
186
+ Maybe.match(() => unit, sink.event),
187
+ ),
188
+ },
189
+ this.__trace,
190
+ ),
191
+ scheduler,
192
+ context,
193
+ )
194
+ }
195
+
196
+ static make<R, E, A, B>(
197
+ stream: Stream<R, E, A>,
198
+ f: (a: A) => Maybe.Maybe<B>,
199
+ __trace?: string,
200
+ ): Stream<R, E, B> {
201
+ if (stream instanceof MapStream) {
202
+ return FilterMapStream.make(stream.stream, flow(stream.f, f), __trace)
203
+ }
204
+
205
+ if (stream instanceof FilterMapStream) {
206
+ return FilterMapStream.make(stream.stream, flow(stream.f, Maybe.flatMap(f)), __trace)
207
+ }
208
+
209
+ return new FilterMapStream(stream, f, __trace)
210
+ }
211
+ }
@@ -8,23 +8,27 @@ import { FiberContext } from '@/FiberContext/FiberContext.js'
8
8
  import { FiberId } from '@/FiberId/FiberId.js'
9
9
  import * as Fx from '@/Fx/index.js'
10
10
  import { Scheduler } from '@/Scheduler/Scheduler.js'
11
- import { Sink } from '@/Sink/Sink.js'
11
+ import { Sink, addTrace } from '@/Sink/Sink.js'
12
12
 
13
- export function continueWith<R2, E2, B>(f: () => Stream<R2, E2, B>) {
13
+ export function continueWith<R2, E2, B>(f: () => Stream<R2, E2, B>, __trace?: string) {
14
14
  return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R2, E | E2, A | B> =>
15
- new ContinueWith(stream, f)
15
+ new ContinueWith(stream, f, __trace)
16
16
  }
17
17
 
18
18
  export const startWith =
19
- <B>(value: B) =>
19
+ <B>(value: B, __trace?: string) =>
20
20
  <R, E, A>(stream: Stream<R, E, A>) =>
21
21
  pipe(
22
22
  now(value),
23
- continueWith(() => stream),
23
+ continueWith(() => stream, __trace),
24
24
  )
25
25
 
26
26
  export class ContinueWith<R, E, A, R2, E2, B> implements Stream<R | R2, E | E2, A | B> {
27
- constructor(readonly stream: Stream<R, E, A>, readonly f: () => Stream<R2, E2, B>) {}
27
+ constructor(
28
+ readonly stream: Stream<R, E, A>,
29
+ readonly f: () => Stream<R2, E2, B>,
30
+ readonly __trace?: string,
31
+ ) {}
28
32
 
29
33
  fork = <E3>(
30
34
  sink: Sink<E | E2, A | B, E3>,
@@ -33,7 +37,7 @@ export class ContinueWith<R, E, A, R2, E2, B> implements Stream<R | R2, E | E2,
33
37
  ) => {
34
38
  return Fx.access((env: Env<R | R2>) =>
35
39
  this.stream.fork(
36
- new ContinueWithSink(sink, scheduler, context, env, this.f),
40
+ addTrace(new ContinueWithSink(sink, scheduler, context, env, this.f), this.__trace),
37
41
  scheduler,
38
42
  context,
39
43
  ),
@@ -0,0 +1,43 @@
1
+ import { Stream } from './Stream.js'
2
+
3
+ import { Env } from '@/Env/Env.js'
4
+ import { FiberContext } from '@/FiberContext/FiberContext.js'
5
+ import { FiberId } from '@/FiberId/FiberId.js'
6
+ import { access, fromLazy } from '@/Fx/index.js'
7
+ import { delayed } from '@/Schedule/Schedule.js'
8
+ import { Scheduler } from '@/Scheduler/Scheduler.js'
9
+ import { Sink } from '@/Sink/Sink.js'
10
+ import { Delay } from '@/Time/index.js'
11
+
12
+ export function delay(delay: Delay) {
13
+ return <R, E, A>(stream: Stream<R, E, A>): Stream<R, E, A> =>
14
+ Stream((sink, scheduler, context) =>
15
+ access((env: Env<R>) =>
16
+ stream.fork(new DelaySink(sink, scheduler, context, env, delay), scheduler, context),
17
+ ),
18
+ )
19
+ }
20
+
21
+ class DelaySink<E, A, E2> implements Sink<E, A, E2> {
22
+ constructor(
23
+ readonly sink: Sink<E, A, E2>,
24
+ readonly scheduler: Scheduler,
25
+ readonly context: FiberContext<FiberId.Live>,
26
+ readonly env: Env<any>,
27
+ readonly delay: Delay,
28
+ ) {}
29
+
30
+ event(value: A) {
31
+ return fromLazy(() =>
32
+ this.scheduler.schedule(
33
+ this.sink.event(value),
34
+ this.env,
35
+ delayed(this.delay),
36
+ this.context.fork(),
37
+ ),
38
+ )
39
+ }
40
+
41
+ error = this.sink.error
42
+ end = this.sink.end
43
+ }
@@ -7,18 +7,18 @@ import { FiberContext } from '@/FiberContext/FiberContext.js'
7
7
  import { FiberId } from '@/FiberId/FiberId.js'
8
8
  import * as Fx from '@/Fx/index.js'
9
9
  import { Scheduler } from '@/Scheduler/Scheduler.js'
10
- import { Drain, Sink, makeDrain } from '@/Sink/Sink.js'
10
+ import { Drain, Sink, addTrace, makeDrain } from '@/Sink/Sink.js'
11
11
 
12
12
  export function drain<R, E, A>(
13
13
  stream: Stream<R, E, A>,
14
14
  __trace?: string,
15
- ): Fx.Fx<R | Scheduler, never, Fiber<E, any>> {
15
+ ): Fx.Fx<R | Scheduler, never, Fiber<never, any>> {
16
16
  return pipe(
17
17
  Fx.Do,
18
18
  Fx.bind('fiberContext', () => Fx.getFiberContext),
19
19
  Fx.let('context', ({ fiberContext }) => fiberContext.fork()),
20
20
  Fx.let('sink', ({ context }) => new Drain<E, A>(context.scope)),
21
- Fx.flatMap(({ sink, context }) => fork(stream, sink, context), __trace),
21
+ Fx.flatMap(({ sink, context }) => fork(stream, sink, context, __trace), __trace),
22
22
  )
23
23
  }
24
24
 
@@ -26,8 +26,9 @@ export function fork<R, E, A, E2 = never>(
26
26
  stream: Stream<R, E, A>,
27
27
  sink: Sink<E, A, E2>,
28
28
  context: FiberContext<FiberId.Live>,
29
- ): Fx.Fx<R | Scheduler, never, Fiber<E | E2, A>> {
30
- return Fx.asks(Scheduler)((scheduler) => stream.fork(sink, scheduler, context))
29
+ __trace?: string,
30
+ ): Fx.Fx<R | Scheduler, never, Fiber<E2, A>> {
31
+ return Fx.asks(Scheduler)((scheduler) => stream.fork(addTrace(sink, __trace), scheduler, context))
31
32
  }
32
33
 
33
34
  export function observe<A, R2, E2, B>(f: (a: A) => Fx.Fx<R2, E2, B>, __trace?: string) {
@@ -37,7 +38,7 @@ export function observe<A, R2, E2, B>(f: (a: A) => Fx.Fx<R2, E2, B>, __trace?: s
37
38
  Fx.bind('fiberContext', () => Fx.getFiberContext),
38
39
  Fx.let('context', ({ fiberContext }) => fiberContext.fork()),
39
40
  Fx.bind('sink', ({ context }) => makeDrain<E, A, R2, E2>(context.scope, { event: f })),
40
- Fx.flatMap(({ sink, context }) => fork(stream, sink, context), __trace),
41
+ Fx.flatMap(({ sink, context }) => fork(stream, sink, context, __trace), __trace),
41
42
  )
42
43
  }
43
44
 
@@ -50,7 +51,7 @@ export function collect<R, E, A>(
50
51
 
51
52
  yield* pipe(
52
53
  stream,
53
- observe((a) => Fx.fromLazy(() => events.push(a))),
54
+ observe((a) => Fx.fromLazy(() => events.push(a)), __trace),
54
55
  Fx.flatMap(Fx.join),
55
56
  )
56
57
 
@@ -1,8 +1,7 @@
1
1
  import { Stream } from './Stream.js'
2
2
 
3
3
  import * as Fx from '@/Fx/Fx.js'
4
- import { span } from '@/Fx/logging.js'
5
4
 
6
5
  export const empty = Stream<never, never, never>((sink, scheduler, context) =>
7
- Fx.asksEnv((env) => scheduler.asap(sink.end, env, context, span('empty'))),
6
+ Fx.asksEnv((env) => scheduler.asap(sink.end, env, context)),
8
7
  )
@@ -2,13 +2,11 @@ import { deepStrictEqual } from 'assert'
2
2
 
3
3
  import { pipe } from 'hkt-ts'
4
4
 
5
- import { collect, observe } from './drain.js'
5
+ import { collectAll } from './_internal.test.js'
6
6
  import { flatMap } from './flatMap.js'
7
7
  import { fromFx } from './fromFx.js'
8
8
 
9
9
  import * as Fx from '@/Fx/index.js'
10
- import { RootScheduler } from '@/Scheduler/RootScheduler.js'
11
- import { Scheduler } from '@/Scheduler/Scheduler.js'
12
10
  import { testSuite } from '@/_internal/suite.js'
13
11
 
14
12
  testSuite(import.meta.url, () => {
@@ -19,25 +17,14 @@ testSuite(import.meta.url, () => {
19
17
  flatMap((a) => fromFx(Fx.success(a + 1))),
20
18
  )
21
19
 
22
- it('should create a Stream', () =>
23
- pipe(
24
- stream,
25
- observe((n) => Fx.fromLazy(() => deepStrictEqual(n, value + 1))),
26
- Fx.flatMap(Fx.join),
27
- Fx.provideService(Scheduler, RootScheduler()),
28
- Fx.runMain,
29
- ))
30
-
31
- it('should be collectable', async () => {
32
- await pipe(
33
- Fx.Fx(function* () {
34
- const events: readonly number[] = yield* collect(stream)
20
+ it('is collectable', async () => {
21
+ const events = await collectAll(stream)
22
+ deepStrictEqual(events, [value + 1])
23
+ })
35
24
 
36
- deepStrictEqual(events, [value + 1])
37
- }),
38
- Fx.provideService(Scheduler, RootScheduler()),
39
- Fx.runMain,
40
- )
25
+ it('is collectable with multiple subscribers', async () => {
26
+ const events = await Promise.all([collectAll(stream), collectAll(stream)])
27
+ deepStrictEqual(events, [[value + 1], [value + 1]])
41
28
  })
42
29
  })
43
30
  })