effect 2.0.0-next.44 → 2.0.0-next.46

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 (779) hide show
  1. package/Bigint/dist/effect-Bigint.cjs.dev.js +125 -1
  2. package/Bigint/dist/effect-Bigint.cjs.mjs +6 -1
  3. package/Bigint/dist/effect-Bigint.cjs.prod.js +125 -1
  4. package/Bigint/dist/effect-Bigint.esm.js +111 -2
  5. package/Boolean/dist/effect-Boolean.cjs.dev.js +1 -1
  6. package/Boolean/dist/effect-Boolean.cjs.prod.js +1 -1
  7. package/Boolean/dist/effect-Boolean.esm.js +1 -1
  8. package/Brand/dist/effect-Brand.cjs.dev.js +3 -3
  9. package/Brand/dist/effect-Brand.cjs.prod.js +3 -3
  10. package/Cache/dist/effect-Cache.cjs.dev.js +32 -32
  11. package/Cache/dist/effect-Cache.cjs.prod.js +32 -32
  12. package/Cause/dist/effect-Cause.cjs.dev.js +17 -17
  13. package/Cause/dist/effect-Cause.cjs.mjs +1 -1
  14. package/Cause/dist/effect-Cause.cjs.prod.js +17 -17
  15. package/Cause/dist/effect-Cause.esm.js +4 -4
  16. package/Channel/dist/effect-Channel.cjs.dev.js +50 -50
  17. package/Channel/dist/effect-Channel.cjs.mjs +3 -3
  18. package/Channel/dist/effect-Channel.cjs.prod.js +50 -50
  19. package/Channel/dist/effect-Channel.esm.js +8 -8
  20. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.dev.js +36 -36
  21. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.prod.js +36 -36
  22. package/Chunk/dist/effect-Chunk.cjs.dev.js +3 -3
  23. package/Chunk/dist/effect-Chunk.cjs.prod.js +3 -3
  24. package/Clock/dist/effect-Clock.cjs.dev.js +16 -16
  25. package/Clock/dist/effect-Clock.cjs.prod.js +16 -16
  26. package/Config/dist/effect-Config.cjs.dev.js +11 -11
  27. package/Config/dist/effect-Config.cjs.prod.js +11 -11
  28. package/ConfigError/dist/effect-ConfigError.cjs.dev.js +4 -4
  29. package/ConfigError/dist/effect-ConfigError.cjs.prod.js +4 -4
  30. package/ConfigProvider/dist/effect-ConfigProvider.cjs.dev.js +17 -17
  31. package/ConfigProvider/dist/effect-ConfigProvider.cjs.prod.js +17 -17
  32. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.dev.js +5 -5
  33. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.prod.js +5 -5
  34. package/ConfigSecret/dist/effect-ConfigSecret.cjs.dev.js +4 -4
  35. package/ConfigSecret/dist/effect-ConfigSecret.cjs.prod.js +4 -4
  36. package/Console/dist/effect-Console.cjs.dev.js +35 -35
  37. package/Console/dist/effect-Console.cjs.prod.js +35 -35
  38. package/Context/dist/effect-Context.cjs.dev.js +3 -8
  39. package/Context/dist/effect-Context.cjs.prod.js +3 -8
  40. package/Data/dist/effect-Data.cjs.dev.js +141 -54
  41. package/Data/dist/effect-Data.cjs.mjs +2 -0
  42. package/Data/dist/effect-Data.cjs.prod.js +141 -54
  43. package/Data/dist/effect-Data.esm.js +51 -3
  44. package/DefaultServices/dist/effect-DefaultServices.cjs.dev.js +16 -16
  45. package/DefaultServices/dist/effect-DefaultServices.cjs.prod.js +16 -16
  46. package/Deferred/dist/effect-Deferred.cjs.dev.js +8 -8
  47. package/Deferred/dist/effect-Deferred.cjs.prod.js +8 -8
  48. package/Differ/dist/effect-Differ.cjs.dev.js +11 -11
  49. package/Differ/dist/effect-Differ.cjs.prod.js +11 -11
  50. package/Duration/dist/effect-Duration.cjs.dev.js +3 -3
  51. package/Duration/dist/effect-Duration.cjs.prod.js +3 -3
  52. package/Effect/dist/effect-Effect.cjs.dev.js +44 -44
  53. package/Effect/dist/effect-Effect.cjs.prod.js +44 -44
  54. package/Effectable/dist/effect-Effectable.cjs.dev.js +24 -14
  55. package/Effectable/dist/effect-Effectable.cjs.mjs +5 -4
  56. package/Effectable/dist/effect-Effectable.cjs.prod.js +24 -14
  57. package/Effectable/dist/effect-Effectable.esm.js +15 -5
  58. package/Either/dist/effect-Either.cjs.dev.js +3 -3
  59. package/Either/dist/effect-Either.cjs.prod.js +3 -3
  60. package/Encoding/dist/effect-Encoding.cjs.dev.js +3 -3
  61. package/Encoding/dist/effect-Encoding.cjs.prod.js +3 -3
  62. package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.dev.js +2 -2
  63. package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.prod.js +2 -2
  64. package/Exit/dist/effect-Exit.cjs.dev.js +8 -8
  65. package/Exit/dist/effect-Exit.cjs.prod.js +8 -8
  66. package/Fiber/dist/effect-Fiber.cjs.dev.js +29 -29
  67. package/Fiber/dist/effect-Fiber.cjs.prod.js +29 -29
  68. package/FiberId/dist/effect-FiberId.cjs.dev.js +5 -5
  69. package/FiberId/dist/effect-FiberId.cjs.prod.js +5 -5
  70. package/FiberRef/dist/effect-FiberRef.cjs.dev.js +29 -29
  71. package/FiberRef/dist/effect-FiberRef.cjs.prod.js +29 -29
  72. package/FiberRefs/dist/effect-FiberRefs.cjs.dev.js +9 -9
  73. package/FiberRefs/dist/effect-FiberRefs.cjs.prod.js +9 -9
  74. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.dev.js +10 -10
  75. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.prod.js +10 -10
  76. package/GroupBy/dist/effect-GroupBy.cjs.dev.js +42 -42
  77. package/GroupBy/dist/effect-GroupBy.cjs.prod.js +42 -42
  78. package/HashMap/dist/effect-HashMap.cjs.dev.js +20 -20
  79. package/HashMap/dist/effect-HashMap.cjs.prod.js +20 -20
  80. package/HashSet/dist/effect-HashSet.cjs.dev.js +20 -20
  81. package/HashSet/dist/effect-HashSet.cjs.prod.js +20 -20
  82. package/KeyedPool/dist/effect-KeyedPool.cjs.dev.js +33 -33
  83. package/KeyedPool/dist/effect-KeyedPool.cjs.prod.js +33 -33
  84. package/Layer/dist/effect-Layer.cjs.dev.js +32 -32
  85. package/Layer/dist/effect-Layer.cjs.prod.js +32 -32
  86. package/List/dist/effect-List.cjs.dev.js +3 -3
  87. package/List/dist/effect-List.cjs.prod.js +3 -3
  88. package/LogLevel/dist/effect-LogLevel.cjs.dev.js +8 -8
  89. package/LogLevel/dist/effect-LogLevel.cjs.prod.js +8 -8
  90. package/Logger/dist/effect-Logger.cjs.dev.js +33 -33
  91. package/Logger/dist/effect-Logger.cjs.prod.js +33 -33
  92. package/Metric/dist/effect-Metric.cjs.dev.js +27 -27
  93. package/Metric/dist/effect-Metric.cjs.prod.js +27 -27
  94. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.dev.js +4 -4
  95. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.prod.js +4 -4
  96. package/MetricHook/dist/effect-MetricHook.cjs.dev.js +6 -6
  97. package/MetricHook/dist/effect-MetricHook.cjs.prod.js +6 -6
  98. package/MetricKey/dist/effect-MetricKey.cjs.dev.js +6 -6
  99. package/MetricKey/dist/effect-MetricKey.cjs.prod.js +6 -6
  100. package/MetricKeyType/dist/effect-MetricKeyType.cjs.dev.js +4 -4
  101. package/MetricKeyType/dist/effect-MetricKeyType.cjs.prod.js +4 -4
  102. package/MetricPolling/dist/effect-MetricPolling.cjs.dev.js +30 -30
  103. package/MetricPolling/dist/effect-MetricPolling.cjs.prod.js +30 -30
  104. package/MetricRegistry/dist/effect-MetricRegistry.cjs.dev.js +8 -8
  105. package/MetricRegistry/dist/effect-MetricRegistry.cjs.prod.js +8 -8
  106. package/MetricState/dist/effect-MetricState.cjs.dev.js +1 -1
  107. package/MetricState/dist/effect-MetricState.cjs.prod.js +1 -1
  108. package/MutableHashMap/dist/effect-MutableHashMap.cjs.dev.js +4 -4
  109. package/MutableHashMap/dist/effect-MutableHashMap.cjs.prod.js +4 -4
  110. package/MutableHashSet/dist/effect-MutableHashSet.cjs.dev.js +4 -4
  111. package/MutableHashSet/dist/effect-MutableHashSet.cjs.prod.js +4 -4
  112. package/MutableQueue/dist/effect-MutableQueue.cjs.dev.js +3 -3
  113. package/MutableQueue/dist/effect-MutableQueue.cjs.prod.js +3 -3
  114. package/Number/dist/effect-Number.cjs.dev.js +1 -1
  115. package/Number/dist/effect-Number.cjs.prod.js +1 -1
  116. package/Number/dist/effect-Number.esm.js +1 -1
  117. package/Option/dist/effect-Option.cjs.dev.js +9 -9
  118. package/Option/dist/effect-Option.cjs.prod.js +9 -9
  119. package/Pool/dist/effect-Pool.cjs.dev.js +31 -31
  120. package/Pool/dist/effect-Pool.cjs.prod.js +31 -31
  121. package/PubSub/dist/effect-PubSub.cjs.d.mts +2 -0
  122. package/PubSub/dist/effect-PubSub.cjs.d.mts.map +1 -0
  123. package/PubSub/dist/effect-PubSub.cjs.d.ts +2 -0
  124. package/PubSub/dist/effect-PubSub.cjs.d.ts.map +1 -0
  125. package/{Hub/dist/effect-Hub.cjs.dev.js → PubSub/dist/effect-PubSub.cjs.dev.js} +163 -163
  126. package/PubSub/dist/effect-PubSub.cjs.js +7 -0
  127. package/{Hub/dist/effect-Hub.cjs.mjs → PubSub/dist/effect-PubSub.cjs.mjs} +1 -1
  128. package/{Hub/dist/effect-Hub.cjs.prod.js → PubSub/dist/effect-PubSub.cjs.prod.js} +163 -163
  129. package/{Hub/dist/effect-Hub.esm.js → PubSub/dist/effect-PubSub.esm.js} +15 -15
  130. package/PubSub/package.json +4 -0
  131. package/Queue/dist/effect-Queue.cjs.dev.js +28 -28
  132. package/Queue/dist/effect-Queue.cjs.prod.js +28 -28
  133. package/README.md +5 -5
  134. package/Random/dist/effect-Random.cjs.dev.js +16 -16
  135. package/Random/dist/effect-Random.cjs.prod.js +16 -16
  136. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.dev.js +3 -3
  137. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.prod.js +3 -3
  138. package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.dev.js +3 -3
  139. package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.prod.js +3 -3
  140. package/RedBlackTree/dist/effect-RedBlackTree.cjs.dev.js +4 -4
  141. package/RedBlackTree/dist/effect-RedBlackTree.cjs.prod.js +4 -4
  142. package/Ref/dist/effect-Ref.cjs.dev.js +9 -9
  143. package/Ref/dist/effect-Ref.cjs.prod.js +9 -9
  144. package/Reloadable/dist/effect-Reloadable.cjs.dev.js +44 -44
  145. package/Reloadable/dist/effect-Reloadable.cjs.prod.js +44 -44
  146. package/Request/dist/effect-Request.cjs.dev.js +29 -29
  147. package/Request/dist/effect-Request.cjs.prod.js +29 -29
  148. package/RequestBlock/dist/effect-RequestBlock.cjs.dev.js +36 -36
  149. package/RequestBlock/dist/effect-RequestBlock.cjs.prod.js +36 -36
  150. package/RequestResolver/dist/effect-RequestResolver.cjs.dev.js +38 -38
  151. package/RequestResolver/dist/effect-RequestResolver.cjs.prod.js +38 -38
  152. package/Resource/dist/effect-Resource.cjs.dev.js +34 -34
  153. package/Resource/dist/effect-Resource.cjs.prod.js +34 -34
  154. package/Runtime/dist/effect-Runtime.cjs.dev.js +34 -34
  155. package/Runtime/dist/effect-Runtime.cjs.prod.js +34 -34
  156. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.dev.js +33 -33
  157. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.prod.js +33 -33
  158. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.dev.js +6 -6
  159. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.prod.js +6 -6
  160. package/STM/dist/effect-STM.cjs.dev.js +48 -48
  161. package/STM/dist/effect-STM.cjs.prod.js +48 -48
  162. package/Schedule/dist/effect-Schedule.cjs.dev.js +19 -19
  163. package/Schedule/dist/effect-Schedule.cjs.prod.js +19 -19
  164. package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.dev.js +3 -3
  165. package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.prod.js +3 -3
  166. package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.dev.js +3 -3
  167. package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.prod.js +3 -3
  168. package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.dev.js +3 -3
  169. package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.prod.js +3 -3
  170. package/Scheduler/dist/effect-Scheduler.cjs.dev.js +8 -8
  171. package/Scheduler/dist/effect-Scheduler.cjs.prod.js +8 -8
  172. package/Scope/dist/effect-Scope.cjs.dev.js +27 -27
  173. package/Scope/dist/effect-Scope.cjs.prod.js +27 -27
  174. package/ScopedCache/dist/effect-ScopedCache.cjs.dev.js +78 -61
  175. package/ScopedCache/dist/effect-ScopedCache.cjs.prod.js +78 -61
  176. package/ScopedRef/dist/effect-ScopedRef.cjs.dev.js +34 -34
  177. package/ScopedRef/dist/effect-ScopedRef.cjs.prod.js +34 -34
  178. package/Sink/dist/effect-Sink.cjs.dev.js +43 -43
  179. package/Sink/dist/effect-Sink.cjs.mjs +1 -1
  180. package/Sink/dist/effect-Sink.cjs.prod.js +43 -43
  181. package/Sink/dist/effect-Sink.esm.js +5 -5
  182. package/SortedMap/dist/effect-SortedMap.cjs.dev.js +3 -3
  183. package/SortedMap/dist/effect-SortedMap.cjs.prod.js +3 -3
  184. package/SortedSet/dist/effect-SortedSet.cjs.dev.js +3 -3
  185. package/SortedSet/dist/effect-SortedSet.cjs.prod.js +3 -3
  186. package/Stream/dist/effect-Stream.cjs.dev.js +60 -60
  187. package/Stream/dist/effect-Stream.cjs.mjs +5 -5
  188. package/Stream/dist/effect-Stream.cjs.prod.js +60 -60
  189. package/Stream/dist/effect-Stream.esm.js +15 -15
  190. package/Streamable/dist/effect-Streamable.cjs.d.mts +2 -0
  191. package/Streamable/dist/effect-Streamable.cjs.d.mts.map +1 -0
  192. package/Streamable/dist/effect-Streamable.cjs.d.ts +2 -0
  193. package/Streamable/dist/effect-Streamable.cjs.d.ts.map +1 -0
  194. package/Streamable/dist/effect-Streamable.cjs.dev.js +152 -0
  195. package/Streamable/dist/effect-Streamable.cjs.js +7 -0
  196. package/Streamable/dist/effect-Streamable.cjs.mjs +3 -0
  197. package/Streamable/dist/effect-Streamable.cjs.prod.js +152 -0
  198. package/Streamable/dist/effect-Streamable.esm.js +42 -0
  199. package/Streamable/package.json +4 -0
  200. package/String/dist/effect-String.cjs.dev.js +4 -4
  201. package/String/dist/effect-String.cjs.prod.js +4 -4
  202. package/String/dist/effect-String.esm.js +1 -1
  203. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.dev.js +48 -48
  204. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.prod.js +48 -48
  205. package/Supervisor/dist/effect-Supervisor.cjs.dev.js +34 -34
  206. package/Supervisor/dist/effect-Supervisor.cjs.prod.js +34 -34
  207. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.dev.js +30 -30
  208. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.prod.js +30 -30
  209. package/TArray/dist/effect-TArray.cjs.dev.js +46 -46
  210. package/TArray/dist/effect-TArray.cjs.prod.js +46 -46
  211. package/TDeferred/dist/effect-TDeferred.cjs.dev.js +45 -45
  212. package/TDeferred/dist/effect-TDeferred.cjs.prod.js +45 -45
  213. package/TMap/dist/effect-TMap.cjs.dev.js +47 -47
  214. package/TMap/dist/effect-TMap.cjs.prod.js +47 -47
  215. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.dev.js +44 -44
  216. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.prod.js +44 -44
  217. package/TPubSub/dist/effect-TPubSub.cjs.d.mts +2 -0
  218. package/TPubSub/dist/effect-TPubSub.cjs.d.mts.map +1 -0
  219. package/TPubSub/dist/effect-TPubSub.cjs.d.ts +2 -0
  220. package/TPubSub/dist/effect-TPubSub.cjs.d.ts.map +1 -0
  221. package/{THub/dist/effect-THub.cjs.dev.js → TPubSub/dist/effect-TPubSub.cjs.dev.js} +101 -101
  222. package/TPubSub/dist/effect-TPubSub.cjs.js +7 -0
  223. package/{THub/dist/effect-THub.cjs.mjs → TPubSub/dist/effect-TPubSub.cjs.mjs} +2 -2
  224. package/{THub/dist/effect-THub.cjs.prod.js → TPubSub/dist/effect-TPubSub.cjs.prod.js} +101 -101
  225. package/TPubSub/dist/effect-TPubSub.esm.js +157 -0
  226. package/TPubSub/package.json +4 -0
  227. package/TQueue/dist/effect-TQueue.cjs.dev.js +46 -46
  228. package/TQueue/dist/effect-TQueue.cjs.prod.js +46 -46
  229. package/TRandom/dist/effect-TRandom.cjs.dev.js +50 -50
  230. package/TRandom/dist/effect-TRandom.cjs.prod.js +50 -50
  231. package/TReentrantLock/dist/effect-TReentrantLock.cjs.dev.js +46 -46
  232. package/TReentrantLock/dist/effect-TReentrantLock.cjs.prod.js +46 -46
  233. package/TRef/dist/effect-TRef.cjs.dev.js +44 -44
  234. package/TRef/dist/effect-TRef.cjs.prod.js +44 -44
  235. package/TSemaphore/dist/effect-TSemaphore.cjs.dev.js +45 -45
  236. package/TSemaphore/dist/effect-TSemaphore.cjs.prod.js +45 -45
  237. package/TSet/dist/effect-TSet.cjs.dev.js +47 -47
  238. package/TSet/dist/effect-TSet.cjs.prod.js +47 -47
  239. package/Take/dist/effect-Take.cjs.dev.js +36 -36
  240. package/Take/dist/effect-Take.cjs.prod.js +36 -36
  241. package/TestAnnotation/dist/effect-TestAnnotation.cjs.dev.js +8 -8
  242. package/TestAnnotation/dist/effect-TestAnnotation.cjs.prod.js +8 -8
  243. package/TestAnnotations/dist/effect-TestAnnotations.cjs.dev.js +25 -25
  244. package/TestAnnotations/dist/effect-TestAnnotations.cjs.prod.js +25 -25
  245. package/TestClock/dist/effect-TestClock.cjs.dev.js +46 -46
  246. package/TestClock/dist/effect-TestClock.cjs.prod.js +46 -46
  247. package/TestConfig/dist/effect-TestConfig.cjs.dev.js +3 -8
  248. package/TestConfig/dist/effect-TestConfig.cjs.prod.js +3 -8
  249. package/TestContext/dist/effect-TestContext.cjs.dev.js +37 -37
  250. package/TestContext/dist/effect-TestContext.cjs.prod.js +37 -37
  251. package/TestLive/dist/effect-TestLive.cjs.dev.js +17 -17
  252. package/TestLive/dist/effect-TestLive.cjs.prod.js +17 -17
  253. package/TestServices/dist/effect-TestServices.cjs.dev.js +42 -42
  254. package/TestServices/dist/effect-TestServices.cjs.prod.js +42 -42
  255. package/TestSized/dist/effect-TestSized.cjs.dev.js +11 -11
  256. package/TestSized/dist/effect-TestSized.cjs.prod.js +11 -11
  257. package/Tracer/dist/effect-Tracer.cjs.dev.js +16 -16
  258. package/Tracer/dist/effect-Tracer.cjs.prod.js +16 -16
  259. package/dist/{Context-01a123ac.cjs.prod.js → Context-9fe5eb16.cjs.prod.js} +5 -5
  260. package/dist/{Context-593661f6.cjs.dev.js → Context-da73ddfa.cjs.dev.js} +5 -5
  261. package/dist/{Effectable-2f022879.cjs.dev.js → Effectable-7314aed8.cjs.dev.js} +63 -10
  262. package/dist/{Effectable-cd8f3a96.cjs.prod.js → Effectable-c4c14a2b.cjs.prod.js} +63 -10
  263. package/dist/{Either-7a881c7a.cjs.prod.js → Either-d43f082c.cjs.prod.js} +6 -79
  264. package/dist/{Either-12bbe00c.cjs.dev.js → Either-fa0ef1d9.cjs.dev.js} +6 -79
  265. package/dist/{ExecutionStrategy-14d3053a.cjs.prod.js → ExecutionStrategy-4808fe5d.cjs.prod.js} +2 -2
  266. package/dist/{ExecutionStrategy-70f1a920.cjs.dev.js → ExecutionStrategy-7d9d457b.cjs.dev.js} +2 -2
  267. package/dist/{HashSet-0b4ff1e4.cjs.dev.js → HashSet-5963ad6b.cjs.dev.js} +32 -32
  268. package/dist/{HashSet-6257b66d.cjs.prod.js → HashSet-ac02a3e1.cjs.prod.js} +32 -32
  269. package/dist/Option-463b42e6.cjs.dev.js +81 -0
  270. package/dist/Option-935e5d7c.cjs.prod.js +81 -0
  271. package/dist/{Ref-a3a4e50d.cjs.prod.js → Ref-4014b526.cjs.prod.js} +1 -1
  272. package/dist/{Ref-74b592a4.cjs.dev.js → Ref-acdee7ef.cjs.dev.js} +1 -1
  273. package/dist/{cache-75fbef45.cjs.prod.js → cache-5c7d77e4.cjs.prod.js} +17 -17
  274. package/dist/{cache-e1ea3923.cjs.dev.js → cache-7eed9d33.cjs.dev.js} +17 -17
  275. package/dist/{circular-6f16b226.cjs.prod.js → circular-1f481ffb.cjs.prod.js} +33 -33
  276. package/dist/{circular-f406f9a4.cjs.prod.js → circular-9e10a5a7.cjs.prod.js} +6 -6
  277. package/dist/{circular-58ff5e9c.cjs.dev.js → circular-c2dbce1a.cjs.dev.js} +33 -33
  278. package/dist/{circular-30564534.cjs.dev.js → circular-c8b65bdb.cjs.dev.js} +6 -6
  279. package/dist/{config-80900693.cjs.dev.js → config-3b7935a3.cjs.dev.js} +3 -3
  280. package/dist/{config-d0ddc159.cjs.prod.js → config-5ba54da1.cjs.prod.js} +3 -3
  281. package/dist/{configProvider-93617d6d.cjs.prod.js → configProvider-b6b20998.cjs.prod.js} +29 -29
  282. package/dist/{configProvider-ce43fdbf.cjs.dev.js → configProvider-f34a82f1.cjs.dev.js} +29 -29
  283. package/dist/{core-0b0539de.cjs.prod.js → core-07202cc0.cjs.prod.js} +711 -726
  284. package/dist/{core-60ca562a.cjs.prod.js → core-7411d1e1.cjs.prod.js} +3 -3
  285. package/dist/{core-b4d7b4f5.cjs.dev.js → core-b7401357.cjs.dev.js} +711 -726
  286. package/dist/{core-13f8a866.cjs.dev.js → core-c5747f88.cjs.dev.js} +3 -3
  287. package/dist/{core-effect-892f3686.cjs.dev.js → core-effect-1c564d42.cjs.dev.js} +77 -75
  288. package/dist/{core-effect-c65770cd.cjs.prod.js → core-effect-9201ea63.cjs.prod.js} +77 -75
  289. package/dist/{dataSource-3ba9e4d3.cjs.dev.js → dataSource-b5eda714.cjs.dev.js} +2 -2
  290. package/dist/{dataSource-7df3a5f6.cjs.prod.js → dataSource-b83bc277.cjs.prod.js} +2 -2
  291. package/dist/declarations/src/Bigint.d.ts +92 -1
  292. package/dist/declarations/src/Bigint.d.ts.map +1 -1
  293. package/dist/declarations/src/Boolean.d.ts +1 -1
  294. package/dist/declarations/src/Cause.d.ts +6 -6
  295. package/dist/declarations/src/Cause.d.ts.map +1 -1
  296. package/dist/declarations/src/Channel.d.ts +7 -7
  297. package/dist/declarations/src/Channel.d.ts.map +1 -1
  298. package/dist/declarations/src/Data.d.ts +30 -0
  299. package/dist/declarations/src/Data.d.ts.map +1 -1
  300. package/dist/declarations/src/Effect.d.ts +4 -2
  301. package/dist/declarations/src/Effect.d.ts.map +1 -1
  302. package/dist/declarations/src/Effectable.d.ts +14 -4
  303. package/dist/declarations/src/Effectable.d.ts.map +1 -1
  304. package/dist/declarations/src/Metric.d.ts +31 -7
  305. package/dist/declarations/src/Metric.d.ts.map +1 -1
  306. package/dist/declarations/src/MetricHook.d.ts +7 -4
  307. package/dist/declarations/src/MetricHook.d.ts.map +1 -1
  308. package/dist/declarations/src/MetricKey.d.ts +24 -4
  309. package/dist/declarations/src/MetricKey.d.ts.map +1 -1
  310. package/dist/declarations/src/MetricKeyType.d.ts +9 -6
  311. package/dist/declarations/src/MetricKeyType.d.ts.map +1 -1
  312. package/dist/declarations/src/MetricRegistry.d.ts +2 -2
  313. package/dist/declarations/src/MetricRegistry.d.ts.map +1 -1
  314. package/dist/declarations/src/MetricState.d.ts +15 -9
  315. package/dist/declarations/src/MetricState.d.ts.map +1 -1
  316. package/dist/declarations/src/Number.d.ts +1 -1
  317. package/dist/declarations/src/{Hub.d.ts → PubSub.d.ts} +38 -38
  318. package/dist/declarations/src/PubSub.d.ts.map +1 -0
  319. package/dist/declarations/src/Sink.d.ts +4 -4
  320. package/dist/declarations/src/Sink.d.ts.map +1 -1
  321. package/dist/declarations/src/Stream.d.ts +24 -24
  322. package/dist/declarations/src/Stream.d.ts.map +1 -1
  323. package/dist/declarations/src/Streamable.d.ts +27 -0
  324. package/dist/declarations/src/Streamable.d.ts.map +1 -0
  325. package/dist/declarations/src/String.d.ts +1 -1
  326. package/dist/declarations/src/SubscriptionRef.d.ts.map +1 -1
  327. package/dist/declarations/src/TPubSub.d.ts +146 -0
  328. package/dist/declarations/src/TPubSub.d.ts.map +1 -0
  329. package/dist/declarations/src/index.d.ts +15 -15
  330. package/dist/declarations/src/index.d.ts.map +1 -1
  331. package/dist/{defaultServices-5530ff0e.cjs.dev.js → defaultServices-755d5b46.cjs.dev.js} +6 -6
  332. package/dist/{defaultServices-086b8ac9.cjs.prod.js → defaultServices-9d7ce86f.cjs.prod.js} +6 -6
  333. package/dist/effect.cjs.dev.js +9 -9
  334. package/dist/effect.cjs.mjs +3 -3
  335. package/dist/effect.cjs.prod.js +9 -9
  336. package/dist/effect.esm.js +6 -6
  337. package/dist/{fiber-1bfb4c1d.cjs.dev.js → fiber-5156eff2.cjs.dev.js} +12 -12
  338. package/dist/{fiber-2eb0a4c1.cjs.prod.js → fiber-9519d109.cjs.prod.js} +12 -12
  339. package/dist/{fiberRefs-be6b6a70.cjs.prod.js → fiberRefs-558c17e6.cjs.prod.js} +1 -1
  340. package/dist/{fiberRefs-be4fae6a.cjs.dev.js → fiberRefs-98b71233.cjs.dev.js} +1 -1
  341. package/dist/{fiberRuntime-2d31e120.cjs.prod.js → fiberRuntime-31ae011f.cjs.prod.js} +99 -100
  342. package/dist/{fiberRuntime-c7280769.cjs.dev.js → fiberRuntime-d3872282.cjs.dev.js} +99 -100
  343. package/dist/{groupBy-0702739b.cjs.prod.js → groupBy-724f64ef.cjs.prod.js} +4 -4
  344. package/dist/{groupBy-7f852bf3.cjs.dev.js → groupBy-862cc2da.cjs.dev.js} +4 -4
  345. package/dist/{hook-e72b20fd.cjs.dev.js → hook-8cefc909.cjs.dev.js} +8 -4
  346. package/dist/{hook-470b717e.cjs.prod.js → hook-98ce30e4.cjs.prod.js} +8 -4
  347. package/dist/{key-f0a1408a.cjs.dev.js → key-198b6670.cjs.dev.js} +3 -3
  348. package/dist/{key-378a6a2c.cjs.prod.js → key-eb8a12b2.cjs.prod.js} +3 -3
  349. package/dist/{keyType-cf67c69c.cjs.prod.js → keyType-0c5e6178.cjs.prod.js} +9 -2
  350. package/dist/{keyType-55f27f07.cjs.dev.js → keyType-7c164b82.cjs.dev.js} +9 -2
  351. package/dist/{layer-b42e8022.cjs.dev.js → layer-29574350.cjs.dev.js} +33 -33
  352. package/dist/{layer-d103b49b.cjs.prod.js → layer-51ff4846.cjs.prod.js} +33 -33
  353. package/dist/{patch-a1b2802f.cjs.dev.js → patch-0220a642.cjs.dev.js} +1 -1
  354. package/dist/{patch-c4d6c61e.cjs.prod.js → patch-7c559bb2.cjs.prod.js} +1 -1
  355. package/dist/{pathPatch-15c8d723.cjs.prod.js → pathPatch-b56a4da2.cjs.prod.js} +1 -1
  356. package/dist/{pathPatch-d9d41297.cjs.dev.js → pathPatch-fab016f1.cjs.dev.js} +1 -1
  357. package/dist/{pool-ef44ba82.cjs.dev.js → pool-3211287f.cjs.dev.js} +31 -31
  358. package/dist/{pool-e414eb88.cjs.prod.js → pool-f77d7705.cjs.prod.js} +31 -31
  359. package/dist/{query-1d0157db.cjs.prod.js → query-a52b25f0.cjs.prod.js} +11 -11
  360. package/dist/{query-54337864.cjs.dev.js → query-c36decd5.cjs.dev.js} +11 -11
  361. package/dist/{queue-27ac9d98.cjs.prod.js → queue-315ea45d.cjs.prod.js} +22 -22
  362. package/dist/{queue-533d70d4.cjs.dev.js → queue-7a223c44.cjs.dev.js} +22 -22
  363. package/dist/{registry-1099de3f.cjs.dev.js → registry-62ff192e.cjs.dev.js} +4 -4
  364. package/dist/{registry-013ecdde.cjs.prod.js → registry-d5258dff.cjs.prod.js} +4 -4
  365. package/dist/{runtime-ea174155.cjs.prod.js → runtime-005f8a9b.cjs.prod.js} +7 -7
  366. package/dist/{runtime-afad6a9b.cjs.dev.js → runtime-57c8ddf8.cjs.dev.js} +7 -7
  367. package/dist/{schedule-1d92198c.cjs.prod.js → schedule-8cdf6bf1.cjs.prod.js} +40 -40
  368. package/dist/{schedule-e0f55cab.cjs.dev.js → schedule-e7a9f93f.cjs.dev.js} +40 -40
  369. package/dist/scopedRef-789d7fef.cjs.prod.js +55 -0
  370. package/dist/scopedRef-eb19c7a6.cjs.dev.js +55 -0
  371. package/dist/{singleProducerAsyncInput-4105a342.cjs.dev.js → singleProducerAsyncInput-9ff8389b.cjs.dev.js} +1 -1
  372. package/dist/{singleProducerAsyncInput-21463e16.cjs.prod.js → singleProducerAsyncInput-f9b258b1.cjs.prod.js} +1 -1
  373. package/dist/{sink-9129504b.cjs.prod.js → sink-572d8981.cjs.prod.js} +17 -17
  374. package/dist/{sink-ee393b63.cjs.dev.js → sink-8d3427e7.cjs.dev.js} +17 -17
  375. package/dist/{state-dd1bd066.cjs.prod.js → state-0bdf02b7.cjs.prod.js} +2 -6
  376. package/dist/{state-8fbec044.cjs.dev.js → state-931050c4.cjs.dev.js} +2 -6
  377. package/dist/{stm-537da66b.cjs.dev.js → stm-8aca0022.cjs.dev.js} +3 -3
  378. package/dist/{stm-5043c3cb.cjs.prod.js → stm-f250b596.cjs.prod.js} +3 -3
  379. package/dist/{stream-c7eda5bc.cjs.dev.js → stream-34d80d2c.cjs.dev.js} +31 -28
  380. package/dist/{stream-13637643.cjs.prod.js → stream-ea4f4d44.cjs.prod.js} +31 -28
  381. package/dist/{synchronizedRef-37e32854.cjs.dev.js → synchronizedRef-a12fd967.cjs.dev.js} +6 -6
  382. package/dist/{synchronizedRef-b4cde4de.cjs.prod.js → synchronizedRef-ed8aa6ac.cjs.prod.js} +6 -6
  383. package/dist/{tArray-df1bae1c.cjs.dev.js → tArray-17f078f2.cjs.dev.js} +3 -3
  384. package/dist/{tArray-d5476a2d.cjs.prod.js → tArray-d184e22f.cjs.prod.js} +3 -3
  385. package/dist/{tMap-a3e14c05.cjs.dev.js → tMap-1a5aa78b.cjs.dev.js} +4 -4
  386. package/dist/{tMap-20ef43ea.cjs.prod.js → tMap-e219f30e.cjs.prod.js} +4 -4
  387. package/dist/{tQueue-bd3cf539.cjs.dev.js → tQueue-0a4fc773.cjs.dev.js} +3 -3
  388. package/dist/{tQueue-c02c22bd.cjs.prod.js → tQueue-47129ad0.cjs.prod.js} +3 -3
  389. package/dist/{tRef-49e44dde.cjs.prod.js → tRef-ab4c5713.cjs.prod.js} +1 -1
  390. package/dist/{tRef-75dd04b3.cjs.dev.js → tRef-b860ef05.cjs.dev.js} +1 -1
  391. package/internal/Context.esm.js +4 -4
  392. package/internal/Data.esm.js +4 -1
  393. package/internal/Differ/ChunkPatch.esm.js +1 -1
  394. package/internal/Differ/ContextPatch.esm.js +1 -1
  395. package/internal/Differ/HashMapPatch.esm.js +1 -1
  396. package/internal/Differ/HashSetPatch.esm.js +1 -1
  397. package/internal/Differ/OrPatch.esm.js +1 -1
  398. package/internal/Effectable.esm.js +9 -9
  399. package/internal/Either.esm.js +3 -3
  400. package/internal/Option.esm.js +3 -3
  401. package/internal/cache.esm.js +1 -1
  402. package/internal/cause.esm.js +6 -21
  403. package/internal/channel.esm.js +5 -5
  404. package/internal/core-effect.esm.js +6 -4
  405. package/internal/fiberRuntime.esm.js +3 -3
  406. package/internal/layer.esm.js +1 -1
  407. package/internal/metric/hook.esm.js +7 -3
  408. package/internal/metric/key.esm.js +2 -2
  409. package/internal/metric/keyType.esm.js +9 -2
  410. package/internal/metric/registry.esm.js +2 -2
  411. package/internal/metric/state.esm.js +2 -6
  412. package/internal/metric.esm.js +3 -3
  413. package/internal/{hub.esm.js → pubsub.esm.js} +108 -108
  414. package/internal/request.esm.js +1 -1
  415. package/internal/sink.esm.js +8 -8
  416. package/internal/stm/{tHub.esm.js → tPubSub.esm.js} +30 -30
  417. package/internal/stream.esm.js +23 -20
  418. package/internal/subscriptionRef.esm.js +8 -8
  419. package/package.json +66 -211
  420. package/src/.index.ts +30 -0
  421. package/src/Bigint.ts +497 -0
  422. package/src/Boolean.ts +261 -0
  423. package/src/Brand.ts +336 -0
  424. package/src/Cache.ts +250 -0
  425. package/src/Cause.ts +813 -0
  426. package/src/Channel.ts +2244 -0
  427. package/src/ChannelChildExecutorDecision.ts +138 -0
  428. package/src/ChannelMergeDecision.ts +94 -0
  429. package/src/ChannelMergeState.ts +166 -0
  430. package/src/ChannelMergeStrategy.ts +107 -0
  431. package/src/ChannelSingleProducerAsyncInput.ts +68 -0
  432. package/src/ChannelUpstreamPullRequest.ts +110 -0
  433. package/src/ChannelUpstreamPullStrategy.ts +120 -0
  434. package/src/Chunk.ts +1314 -0
  435. package/src/Clock.ts +111 -0
  436. package/src/Config.ts +447 -0
  437. package/src/ConfigError.ts +267 -0
  438. package/src/ConfigProvider.ts +296 -0
  439. package/src/ConfigProviderPathPatch.ts +100 -0
  440. package/src/ConfigSecret.ts +76 -0
  441. package/src/Console.ts +222 -0
  442. package/src/Context.ts +365 -0
  443. package/src/Data.ts +367 -0
  444. package/src/DefaultServices.ts +34 -0
  445. package/src/Deferred.ts +283 -0
  446. package/src/Differ.ts +406 -0
  447. package/src/Duration.ts +558 -0
  448. package/src/Effect.ts +5177 -0
  449. package/src/Effectable.ts +107 -0
  450. package/src/Either.ts +593 -0
  451. package/src/Encoding.ts +130 -0
  452. package/src/Equal.ts +64 -0
  453. package/src/Equivalence.ts +235 -0
  454. package/src/ExecutionStrategy.ts +111 -0
  455. package/src/Exit.ts +464 -0
  456. package/src/Fiber.ts +650 -0
  457. package/src/FiberId.ts +187 -0
  458. package/src/FiberRef.ts +399 -0
  459. package/src/FiberRefs.ts +160 -0
  460. package/src/FiberRefsPatch.ts +105 -0
  461. package/src/FiberStatus.ts +108 -0
  462. package/src/Function.ts +834 -0
  463. package/src/GlobalValue.ts +20 -0
  464. package/src/GroupBy.ts +102 -0
  465. package/src/HKT.ts +44 -0
  466. package/src/Hash.ts +162 -0
  467. package/src/HashMap.ts +373 -0
  468. package/src/HashSet.ts +300 -0
  469. package/src/Inspectable.ts +45 -0
  470. package/src/KeyedPool.ts +160 -0
  471. package/src/Layer.ts +866 -0
  472. package/src/List.ts +942 -0
  473. package/src/LogLevel.ts +266 -0
  474. package/src/LogSpan.ts +25 -0
  475. package/src/Logger.ts +321 -0
  476. package/src/Metric.ts +657 -0
  477. package/src/MetricBoundaries.ts +70 -0
  478. package/src/MetricHook.ts +139 -0
  479. package/src/MetricKey.ts +227 -0
  480. package/src/MetricKeyType.ts +257 -0
  481. package/src/MetricLabel.ts +47 -0
  482. package/src/MetricPair.ts +70 -0
  483. package/src/MetricPolling.ts +136 -0
  484. package/src/MetricRegistry.ts +47 -0
  485. package/src/MetricState.ts +256 -0
  486. package/src/MutableHashMap.ts +187 -0
  487. package/src/MutableHashSet.ts +118 -0
  488. package/src/MutableList.ts +289 -0
  489. package/src/MutableQueue.ts +227 -0
  490. package/src/MutableRef.ts +204 -0
  491. package/src/NonEmptyIterable.ts +30 -0
  492. package/src/Number.ts +406 -0
  493. package/src/Option.ts +1307 -0
  494. package/src/Order.ts +328 -0
  495. package/src/Ordering.ts +112 -0
  496. package/src/Pipeable.ts +318 -0
  497. package/src/Pool.ts +148 -0
  498. package/src/Predicate.ts +704 -0
  499. package/src/PubSub.ts +175 -0
  500. package/src/Queue.ts +575 -0
  501. package/src/Random.ts +115 -0
  502. package/src/ReadonlyArray.ts +2017 -0
  503. package/src/ReadonlyRecord.ts +641 -0
  504. package/src/RedBlackTree.ts +415 -0
  505. package/src/Ref.ts +159 -0
  506. package/src/Reloadable.ts +136 -0
  507. package/src/Request.ts +285 -0
  508. package/src/RequestBlock.ts +157 -0
  509. package/src/RequestResolver.ts +305 -0
  510. package/src/Resource.ts +97 -0
  511. package/src/Runtime.ts +216 -0
  512. package/src/RuntimeFlags.ts +336 -0
  513. package/src/RuntimeFlagsPatch.ts +183 -0
  514. package/src/STM.ts +2076 -0
  515. package/src/Schedule.ts +1396 -0
  516. package/src/ScheduleDecision.ts +62 -0
  517. package/src/ScheduleInterval.ts +151 -0
  518. package/src/ScheduleIntervals.ts +122 -0
  519. package/src/Scheduler.ts +359 -0
  520. package/src/Scope.ts +171 -0
  521. package/src/ScopedCache.ts +148 -0
  522. package/src/ScopedRef.ts +95 -0
  523. package/src/Sink.ts +1431 -0
  524. package/src/SortedMap.ts +229 -0
  525. package/src/SortedSet.ts +385 -0
  526. package/src/Stream.ts +4540 -0
  527. package/src/StreamEmit.ts +83 -0
  528. package/src/StreamHaltStrategy.ts +111 -0
  529. package/src/Streamable.ts +42 -0
  530. package/src/String.ts +682 -0
  531. package/src/Struct.ts +151 -0
  532. package/src/SubscriptionRef.ts +273 -0
  533. package/src/Supervisor.ts +239 -0
  534. package/src/Symbol.ts +28 -0
  535. package/src/SynchronizedRef.ts +249 -0
  536. package/src/TArray.ts +494 -0
  537. package/src/TDeferred.ts +99 -0
  538. package/src/TMap.ts +510 -0
  539. package/src/TPriorityQueue.ts +223 -0
  540. package/src/TPubSub.ts +187 -0
  541. package/src/TQueue.ts +431 -0
  542. package/src/TRandom.ts +129 -0
  543. package/src/TReentrantLock.ts +224 -0
  544. package/src/TRef.ts +176 -0
  545. package/src/TSemaphore.ts +129 -0
  546. package/src/TSet.ts +349 -0
  547. package/src/Take.ts +257 -0
  548. package/src/TestAnnotation.ts +166 -0
  549. package/src/TestAnnotationMap.ts +124 -0
  550. package/src/TestAnnotations.ts +113 -0
  551. package/src/TestClock.ts +552 -0
  552. package/src/TestConfig.ts +49 -0
  553. package/src/TestContext.ts +35 -0
  554. package/src/TestLive.ts +55 -0
  555. package/src/TestServices.ts +392 -0
  556. package/src/TestSized.ts +55 -0
  557. package/src/Tracer.ts +119 -0
  558. package/src/Tuple.ts +204 -0
  559. package/src/Types.ts +123 -0
  560. package/src/Unify.ts +118 -0
  561. package/src/Utils.ts +699 -0
  562. package/src/index.ts +840 -0
  563. package/src/internal/Common.ts +56 -0
  564. package/src/internal/Context.ts +252 -0
  565. package/src/internal/Data.ts +55 -0
  566. package/src/internal/Differ/ChunkPatch.ts +209 -0
  567. package/src/internal/Differ/ContextPatch.ts +229 -0
  568. package/src/internal/Differ/HashMapPatch.ts +217 -0
  569. package/src/internal/Differ/HashSetPatch.ts +174 -0
  570. package/src/internal/Differ/OrPatch.ts +296 -0
  571. package/src/internal/Differ.ts +184 -0
  572. package/src/internal/Effectable.ts +92 -0
  573. package/src/internal/Either.ts +107 -0
  574. package/src/internal/Encoding/Base64.ts +282 -0
  575. package/src/internal/Encoding/Base64Url.ts +28 -0
  576. package/src/internal/Encoding/Common.ts +24 -0
  577. package/src/internal/Encoding/Hex.ts +315 -0
  578. package/src/internal/HashMap/array.ts +49 -0
  579. package/src/internal/HashMap/bitwise.ts +32 -0
  580. package/src/internal/HashMap/config.ts +14 -0
  581. package/src/internal/HashMap/keySet.ts +8 -0
  582. package/src/internal/HashMap/node.ts +390 -0
  583. package/src/internal/HashMap.ts +533 -0
  584. package/src/internal/HashSet.ts +319 -0
  585. package/src/internal/Iterable.ts +54 -0
  586. package/src/internal/Option.ts +79 -0
  587. package/src/internal/ReadonlyArray.ts +8 -0
  588. package/src/internal/RedBlackTree/iterator.ts +207 -0
  589. package/src/internal/RedBlackTree/node.ts +48 -0
  590. package/src/internal/RedBlackTree.ts +1195 -0
  591. package/src/internal/Stack.ts +4 -0
  592. package/src/internal/blockedRequests.ts +512 -0
  593. package/src/internal/cache.ts +714 -0
  594. package/src/internal/cause.ts +1205 -0
  595. package/src/internal/channel/channelExecutor.ts +1193 -0
  596. package/src/internal/channel/channelState.ts +132 -0
  597. package/src/internal/channel/childExecutorDecision.ts +95 -0
  598. package/src/internal/channel/continuation.ts +171 -0
  599. package/src/internal/channel/mergeDecision.ts +115 -0
  600. package/src/internal/channel/mergeState.ts +120 -0
  601. package/src/internal/channel/mergeStrategy.ts +72 -0
  602. package/src/internal/channel/singleProducerAsyncInput.ts +261 -0
  603. package/src/internal/channel/subexecutor.ts +229 -0
  604. package/src/internal/channel/upstreamPullRequest.ts +83 -0
  605. package/src/internal/channel/upstreamPullStrategy.ts +86 -0
  606. package/src/internal/channel.ts +2516 -0
  607. package/src/internal/clock.ts +97 -0
  608. package/src/internal/completedRequestMap.ts +9 -0
  609. package/src/internal/concurrency.ts +83 -0
  610. package/src/internal/config.ts +598 -0
  611. package/src/internal/configError.ts +291 -0
  612. package/src/internal/configProvider/pathPatch.ts +97 -0
  613. package/src/internal/configProvider.ts +692 -0
  614. package/src/internal/configSecret.ts +71 -0
  615. package/src/internal/console.ts +136 -0
  616. package/src/internal/core-effect.ts +2146 -0
  617. package/src/internal/core-stream.ts +999 -0
  618. package/src/internal/core.ts +2765 -0
  619. package/src/internal/dataSource.ts +258 -0
  620. package/src/internal/defaultServices/console.ts +97 -0
  621. package/src/internal/defaultServices.ts +140 -0
  622. package/src/internal/deferred.ts +44 -0
  623. package/src/internal/effect/circular.ts +664 -0
  624. package/src/internal/executionStrategy.ts +72 -0
  625. package/src/internal/fiber.ts +350 -0
  626. package/src/internal/fiberId.ts +270 -0
  627. package/src/internal/fiberMessage.ts +85 -0
  628. package/src/internal/fiberRefs/patch.ts +144 -0
  629. package/src/internal/fiberRefs.ts +239 -0
  630. package/src/internal/fiberRuntime.ts +3477 -0
  631. package/src/internal/fiberScope.ts +72 -0
  632. package/src/internal/fiberStatus.ts +118 -0
  633. package/src/internal/groupBy.ts +516 -0
  634. package/src/internal/keyedPool.ts +240 -0
  635. package/src/internal/layer/circular.ts +203 -0
  636. package/src/internal/layer.ts +1230 -0
  637. package/src/internal/logSpan.ts +15 -0
  638. package/src/internal/logger-circular.ts +24 -0
  639. package/src/internal/logger.ts +307 -0
  640. package/src/internal/metric/boundaries.ts +72 -0
  641. package/src/internal/metric/hook.ts +459 -0
  642. package/src/internal/metric/key.ts +173 -0
  643. package/src/internal/metric/keyType.ts +263 -0
  644. package/src/internal/metric/label.ts +44 -0
  645. package/src/internal/metric/pair.ts +48 -0
  646. package/src/internal/metric/polling.ts +143 -0
  647. package/src/internal/metric/registry.ts +188 -0
  648. package/src/internal/metric/state.ts +286 -0
  649. package/src/internal/metric.ts +522 -0
  650. package/src/internal/opCodes/cause.ts +35 -0
  651. package/src/internal/opCodes/channel.ts +83 -0
  652. package/src/internal/opCodes/channelChildExecutorDecision.ts +17 -0
  653. package/src/internal/opCodes/channelMergeDecision.ts +11 -0
  654. package/src/internal/opCodes/channelMergeState.ts +17 -0
  655. package/src/internal/opCodes/channelMergeStrategy.ts +11 -0
  656. package/src/internal/opCodes/channelState.ts +23 -0
  657. package/src/internal/opCodes/channelUpstreamPullRequest.ts +11 -0
  658. package/src/internal/opCodes/channelUpstreamPullStrategy.ts +11 -0
  659. package/src/internal/opCodes/config.ts +65 -0
  660. package/src/internal/opCodes/configError.ts +35 -0
  661. package/src/internal/opCodes/continuation.ts +11 -0
  662. package/src/internal/opCodes/deferred.ts +11 -0
  663. package/src/internal/opCodes/effect.ts +83 -0
  664. package/src/internal/opCodes/layer.ts +53 -0
  665. package/src/internal/opCodes/streamHaltStrategy.ts +23 -0
  666. package/src/internal/pool.ts +499 -0
  667. package/src/internal/pubsub.ts +1557 -0
  668. package/src/internal/query.ts +199 -0
  669. package/src/internal/queue.ts +729 -0
  670. package/src/internal/random.ts +88 -0
  671. package/src/internal/ref.ts +164 -0
  672. package/src/internal/reloadable.ts +164 -0
  673. package/src/internal/request.ts +137 -0
  674. package/src/internal/resource.ts +64 -0
  675. package/src/internal/ringBuffer.ts +68 -0
  676. package/src/internal/runtime.ts +348 -0
  677. package/src/internal/runtimeFlags.ts +176 -0
  678. package/src/internal/runtimeFlagsPatch.ts +103 -0
  679. package/src/internal/schedule/decision.ts +47 -0
  680. package/src/internal/schedule/interval.ts +101 -0
  681. package/src/internal/schedule/intervals.ts +179 -0
  682. package/src/internal/schedule.ts +2096 -0
  683. package/src/internal/scopedCache.ts +634 -0
  684. package/src/internal/scopedRef.ts +133 -0
  685. package/src/internal/singleShotGen.ts +35 -0
  686. package/src/internal/sink.ts +2118 -0
  687. package/src/internal/stm/core.ts +804 -0
  688. package/src/internal/stm/opCodes/stm.ts +71 -0
  689. package/src/internal/stm/opCodes/stmState.ts +17 -0
  690. package/src/internal/stm/opCodes/strategy.ts +17 -0
  691. package/src/internal/stm/opCodes/tExit.ts +29 -0
  692. package/src/internal/stm/opCodes/tryCommit.ts +11 -0
  693. package/src/internal/stm/stm/entry.ts +59 -0
  694. package/src/internal/stm/stm/journal.ts +123 -0
  695. package/src/internal/stm/stm/opCodes/stm.ts +71 -0
  696. package/src/internal/stm/stm/opCodes/stmState.ts +17 -0
  697. package/src/internal/stm/stm/opCodes/strategy.ts +17 -0
  698. package/src/internal/stm/stm/opCodes/tExit.ts +29 -0
  699. package/src/internal/stm/stm/opCodes/tryCommit.ts +11 -0
  700. package/src/internal/stm/stm/stmState.ts +130 -0
  701. package/src/internal/stm/stm/tExit.ts +180 -0
  702. package/src/internal/stm/stm/tryCommit.ts +34 -0
  703. package/src/internal/stm/stm/txnId.ts +14 -0
  704. package/src/internal/stm/stm/versioned.ts +4 -0
  705. package/src/internal/stm/stm.ts +1491 -0
  706. package/src/internal/stm/tArray.ts +550 -0
  707. package/src/internal/stm/tDeferred.ts +79 -0
  708. package/src/internal/stm/tMap.ts +824 -0
  709. package/src/internal/stm/tPriorityQueue.ts +259 -0
  710. package/src/internal/stm/tPubSub.ts +542 -0
  711. package/src/internal/stm/tQueue.ts +400 -0
  712. package/src/internal/stm/tRandom.ts +140 -0
  713. package/src/internal/stm/tReentrantLock.ts +352 -0
  714. package/src/internal/stm/tRef.ts +190 -0
  715. package/src/internal/stm/tSemaphore.ts +113 -0
  716. package/src/internal/stm/tSet.ts +237 -0
  717. package/src/internal/stream/debounceState.ts +57 -0
  718. package/src/internal/stream/emit.ts +46 -0
  719. package/src/internal/stream/haltStrategy.ts +85 -0
  720. package/src/internal/stream/handoff.ts +185 -0
  721. package/src/internal/stream/handoffSignal.ts +59 -0
  722. package/src/internal/stream/pull.ts +35 -0
  723. package/src/internal/stream/sinkEndReason.ts +30 -0
  724. package/src/internal/stream/zipAllState.ts +88 -0
  725. package/src/internal/stream/zipChunksState.ts +56 -0
  726. package/src/internal/stream.ts +8089 -0
  727. package/src/internal/string-utils.ts +107 -0
  728. package/src/internal/subscriptionRef.ts +133 -0
  729. package/src/internal/supervisor/patch.ts +190 -0
  730. package/src/internal/supervisor.ts +301 -0
  731. package/src/internal/synchronizedRef.ts +115 -0
  732. package/src/internal/take.ts +198 -0
  733. package/src/internal/testing/sleep.ts +27 -0
  734. package/src/internal/testing/suspendedWarningData.ts +85 -0
  735. package/src/internal/testing/warningData.ts +94 -0
  736. package/src/internal/timeout.ts +23 -0
  737. package/src/internal/tracer.ts +74 -0
  738. package/Error/dist/effect-Error.cjs.d.mts +0 -2
  739. package/Error/dist/effect-Error.cjs.d.mts.map +0 -1
  740. package/Error/dist/effect-Error.cjs.d.ts +0 -2
  741. package/Error/dist/effect-Error.cjs.d.ts.map +0 -1
  742. package/Error/dist/effect-Error.cjs.dev.js +0 -140
  743. package/Error/dist/effect-Error.cjs.js +0 -7
  744. package/Error/dist/effect-Error.cjs.mjs +0 -4
  745. package/Error/dist/effect-Error.cjs.prod.js +0 -140
  746. package/Error/dist/effect-Error.esm.js +0 -47
  747. package/Error/package.json +0 -4
  748. package/Hub/dist/effect-Hub.cjs.d.mts +0 -2
  749. package/Hub/dist/effect-Hub.cjs.d.mts.map +0 -1
  750. package/Hub/dist/effect-Hub.cjs.d.ts +0 -2
  751. package/Hub/dist/effect-Hub.cjs.d.ts.map +0 -1
  752. package/Hub/dist/effect-Hub.cjs.js +0 -7
  753. package/Hub/package.json +0 -4
  754. package/THub/dist/effect-THub.cjs.d.mts +0 -2
  755. package/THub/dist/effect-THub.cjs.d.mts.map +0 -1
  756. package/THub/dist/effect-THub.cjs.d.ts +0 -2
  757. package/THub/dist/effect-THub.cjs.d.ts.map +0 -1
  758. package/THub/dist/effect-THub.cjs.js +0 -7
  759. package/THub/dist/effect-THub.esm.js +0 -157
  760. package/THub/package.json +0 -4
  761. package/dist/declarations/src/Error.d.ts +0 -37
  762. package/dist/declarations/src/Error.d.ts.map +0 -1
  763. package/dist/declarations/src/Hub.d.ts.map +0 -1
  764. package/dist/declarations/src/THub.d.ts +0 -146
  765. package/dist/declarations/src/THub.d.ts.map +0 -1
  766. package/dist/scopedRef-1c2c9acf.cjs.prod.js +0 -55
  767. package/dist/scopedRef-ab4c58b0.cjs.dev.js +0 -55
  768. /package/dist/{FiberId-e594f6e8.cjs.prod.js → FiberId-1d7ac632.cjs.prod.js} +0 -0
  769. /package/dist/{FiberId-557db880.cjs.dev.js → FiberId-d88ddce6.cjs.dev.js} +0 -0
  770. /package/dist/{RuntimeFlagsPatch-ea268c50.cjs.dev.js → RuntimeFlagsPatch-69102b03.cjs.dev.js} +0 -0
  771. /package/dist/{RuntimeFlagsPatch-e2769b87.cjs.prod.js → RuntimeFlagsPatch-866fa259.cjs.prod.js} +0 -0
  772. /package/dist/{boundaries-20cfad9d.cjs.prod.js → boundaries-9af538e3.cjs.prod.js} +0 -0
  773. /package/dist/{boundaries-3810d885.cjs.dev.js → boundaries-f212e414.cjs.dev.js} +0 -0
  774. /package/dist/{configError-33e55472.cjs.prod.js → configError-b43723af.cjs.prod.js} +0 -0
  775. /package/dist/{configError-240e9b61.cjs.dev.js → configError-d5efe9c0.cjs.dev.js} +0 -0
  776. /package/dist/{configSecret-e34c1b14.cjs.dev.js → configSecret-3e8ae336.cjs.dev.js} +0 -0
  777. /package/dist/{configSecret-d1caca55.cjs.prod.js → configSecret-e2faa181.cjs.prod.js} +0 -0
  778. /package/dist/{take-2af6e92a.cjs.prod.js → take-85daaf79.cjs.prod.js} +0 -0
  779. /package/dist/{take-df9480a8.cjs.dev.js → take-f9ef9e2e.cjs.dev.js} +0 -0
@@ -0,0 +1,1557 @@
1
+ import * as Chunk from "../Chunk"
2
+ import type * as Deferred from "../Deferred"
3
+ import type * as Effect from "../Effect"
4
+ import { dual, pipe } from "../Function"
5
+ import * as MutableQueue from "../MutableQueue"
6
+ import * as MutableRef from "../MutableRef"
7
+ import * as Option from "../Option"
8
+ import { pipeArguments } from "../Pipeable"
9
+ import type * as PubSub from "../PubSub"
10
+ import type * as Queue from "../Queue"
11
+ import type * as Scope from "../Scope"
12
+ import * as cause from "./cause"
13
+ import * as core from "./core"
14
+ import * as executionStrategy from "./executionStrategy"
15
+ import * as fiberRuntime from "./fiberRuntime"
16
+ import * as queue from "./queue"
17
+
18
+ /** @internal */
19
+ export interface AtomicPubSub<A> {
20
+ readonly capacity: number
21
+ isEmpty(): boolean
22
+ isFull(): boolean
23
+ size(): number
24
+ publish(value: A): boolean
25
+ publishAll(elements: Iterable<A>): Chunk.Chunk<A>
26
+ slide(): void
27
+ subscribe(): Subscription<A>
28
+ }
29
+
30
+ /** @internal */
31
+ interface Subscription<A> {
32
+ isEmpty(): boolean
33
+ size(): number
34
+ poll<D>(default_: D): A | D
35
+ pollUpTo(n: number): Chunk.Chunk<A>
36
+ unsubscribe(): void
37
+ }
38
+
39
+ /** @internal */
40
+ type Subscribers<A> = Map<
41
+ Subscription<A>,
42
+ Set<MutableQueue.MutableQueue<Deferred.Deferred<never, A>>>
43
+ >
44
+
45
+ const addSubscribers = <A>(
46
+ subscription: Subscription<A>,
47
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
48
+ ) =>
49
+ (subscribers: Subscribers<A>) => {
50
+ if (!subscribers.has(subscription)) {
51
+ subscribers.set(subscription, new Set())
52
+ }
53
+ const set = subscribers.get(subscription)!
54
+ set.add(pollers)
55
+ }
56
+
57
+ const removeSubscribers = <A>(
58
+ subscription: Subscription<A>,
59
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
60
+ ) =>
61
+ (subscribers: Subscribers<A>) => {
62
+ if (!subscribers.has(subscription)) {
63
+ return
64
+ }
65
+ const set = subscribers.get(subscription)!
66
+ set.delete(pollers)
67
+ if (set.size === 0) {
68
+ subscribers.delete(subscription)
69
+ }
70
+ }
71
+
72
+ /** @internal */
73
+ export const bounded = <A>(requestedCapacity: number): Effect.Effect<never, never, PubSub.PubSub<A>> =>
74
+ pipe(
75
+ core.sync(() => makeBoundedPubSub<A>(requestedCapacity)),
76
+ core.flatMap((atomicPubSub) => makePubSub(atomicPubSub, new BackPressureStrategy()))
77
+ )
78
+
79
+ /** @internal */
80
+ export const dropping = <A>(requestedCapacity: number): Effect.Effect<never, never, PubSub.PubSub<A>> =>
81
+ pipe(
82
+ core.sync(() => makeBoundedPubSub<A>(requestedCapacity)),
83
+ core.flatMap((atomicPubSub) => makePubSub(atomicPubSub, new DroppingStrategy()))
84
+ )
85
+
86
+ /** @internal */
87
+ export const sliding = <A>(requestedCapacity: number): Effect.Effect<never, never, PubSub.PubSub<A>> =>
88
+ pipe(
89
+ core.sync(() => makeBoundedPubSub<A>(requestedCapacity)),
90
+ core.flatMap((atomicPubSub) => makePubSub(atomicPubSub, new SlidingStrategy()))
91
+ )
92
+
93
+ /** @internal */
94
+ export const unbounded = <A>(): Effect.Effect<never, never, PubSub.PubSub<A>> =>
95
+ pipe(
96
+ core.sync(() => makeUnboundedPubSub<A>()),
97
+ core.flatMap((atomicPubSub) => makePubSub(atomicPubSub, new DroppingStrategy()))
98
+ )
99
+
100
+ /** @internal */
101
+ export const capacity = <A>(self: PubSub.PubSub<A>): number => self.capacity()
102
+
103
+ /** @internal */
104
+ export const size = <A>(self: PubSub.PubSub<A>): Effect.Effect<never, never, number> => self.size()
105
+
106
+ /** @internal */
107
+ export const isFull = <A>(self: PubSub.PubSub<A>): Effect.Effect<never, never, boolean> => self.isFull()
108
+
109
+ /** @internal */
110
+ export const isEmpty = <A>(self: PubSub.PubSub<A>): Effect.Effect<never, never, boolean> => self.isEmpty()
111
+
112
+ /** @internal */
113
+ export const shutdown = <A>(self: PubSub.PubSub<A>): Effect.Effect<never, never, void> => self.shutdown()
114
+
115
+ /** @internal */
116
+ export const isShutdown = <A>(self: PubSub.PubSub<A>): Effect.Effect<never, never, boolean> => self.isShutdown()
117
+
118
+ /** @internal */
119
+ export const awaitShutdown = <A>(self: PubSub.PubSub<A>): Effect.Effect<never, never, void> => self.awaitShutdown()
120
+
121
+ /** @internal */
122
+ export const publish = dual<
123
+ <A>(value: A) => (self: PubSub.PubSub<A>) => Effect.Effect<never, never, boolean>,
124
+ <A>(self: PubSub.PubSub<A>, value: A) => Effect.Effect<never, never, boolean>
125
+ >(2, (self, value) => self.publish(value))
126
+
127
+ /** @internal */
128
+ export const publishAll = dual<
129
+ <A>(elements: Iterable<A>) => (self: PubSub.PubSub<A>) => Effect.Effect<never, never, boolean>,
130
+ <A>(self: PubSub.PubSub<A>, elements: Iterable<A>) => Effect.Effect<never, never, boolean>
131
+ >(2, (self, elements) => self.publishAll(elements))
132
+
133
+ /** @internal */
134
+ export const subscribe = <A>(self: PubSub.PubSub<A>): Effect.Effect<Scope.Scope, never, Queue.Dequeue<A>> =>
135
+ self.subscribe()
136
+
137
+ /** @internal */
138
+ const makeBoundedPubSub = <A>(requestedCapacity: number): AtomicPubSub<A> => {
139
+ ensureCapacity(requestedCapacity)
140
+ if (requestedCapacity === 1) {
141
+ return new BoundedPubSubSingle()
142
+ } else if (nextPow2(requestedCapacity) === requestedCapacity) {
143
+ return new BoundedPubSubPow2(requestedCapacity)
144
+ } else {
145
+ return new BoundedPubSubArb(requestedCapacity)
146
+ }
147
+ }
148
+
149
+ /** @internal */
150
+ const makeUnboundedPubSub = <A>(): AtomicPubSub<A> => {
151
+ return new UnboundedPubSub()
152
+ }
153
+
154
+ /** @internal */
155
+ const makeSubscription = <A>(
156
+ pubsub: AtomicPubSub<A>,
157
+ subscribers: Subscribers<A>,
158
+ strategy: PubSubStrategy<A>
159
+ ): Effect.Effect<never, never, Queue.Dequeue<A>> =>
160
+ core.map(core.deferredMake<never, void>(), (deferred) =>
161
+ unsafeMakeSubscription(
162
+ pubsub,
163
+ subscribers,
164
+ pubsub.subscribe(),
165
+ MutableQueue.unbounded<Deferred.Deferred<never, A>>(),
166
+ deferred,
167
+ MutableRef.make(false),
168
+ strategy
169
+ ))
170
+
171
+ /** @internal */
172
+ export const unsafeMakeSubscription = <A>(
173
+ pubsub: AtomicPubSub<A>,
174
+ subscribers: Subscribers<A>,
175
+ subscription: Subscription<A>,
176
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>,
177
+ shutdownHook: Deferred.Deferred<never, void>,
178
+ shutdownFlag: MutableRef.MutableRef<boolean>,
179
+ strategy: PubSubStrategy<A>
180
+ ): Queue.Dequeue<A> => {
181
+ return new SubscriptionImpl(
182
+ pubsub,
183
+ subscribers,
184
+ subscription,
185
+ pollers,
186
+ shutdownHook,
187
+ shutdownFlag,
188
+ strategy
189
+ )
190
+ }
191
+
192
+ /** @internal */
193
+ class BoundedPubSubArb<A> implements AtomicPubSub<A> {
194
+ array: Array<A>
195
+ publisherIndex = 0
196
+ subscribers: Array<number>
197
+ subscriberCount = 0
198
+ subscribersIndex = 0
199
+
200
+ readonly capacity: number
201
+
202
+ constructor(requestedCapacity: number) {
203
+ this.array = Array.from({ length: requestedCapacity })
204
+ this.subscribers = Array.from({ length: requestedCapacity })
205
+ this.capacity = requestedCapacity
206
+ }
207
+
208
+ isEmpty(): boolean {
209
+ return this.publisherIndex === this.subscribersIndex
210
+ }
211
+
212
+ isFull(): boolean {
213
+ return this.publisherIndex === this.subscribersIndex + this.capacity
214
+ }
215
+
216
+ size(): number {
217
+ return this.publisherIndex - this.subscribersIndex
218
+ }
219
+
220
+ publish(value: A): boolean {
221
+ if (this.isFull()) {
222
+ return false
223
+ }
224
+ if (this.subscriberCount !== 0) {
225
+ const index = this.publisherIndex % this.capacity
226
+ this.array[index] = value
227
+ this.subscribers[index] = this.subscriberCount
228
+ this.publisherIndex += 1
229
+ }
230
+ return true
231
+ }
232
+
233
+ publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
234
+ const chunk = Chunk.fromIterable(elements)
235
+ const n = chunk.length
236
+ const size = this.publisherIndex - this.subscribersIndex
237
+ const available = this.capacity - size
238
+ const forPubSub = Math.min(n, available)
239
+ if (forPubSub === 0) {
240
+ return chunk
241
+ }
242
+ let iteratorIndex = 0
243
+ const publishAllIndex = this.publisherIndex + forPubSub
244
+ while (this.publisherIndex !== publishAllIndex) {
245
+ const a = Chunk.unsafeGet(chunk, iteratorIndex++)
246
+ const index = this.publisherIndex % this.capacity
247
+ this.array[index] = a
248
+ this.subscribers[index] = this.subscriberCount
249
+ this.publisherIndex += 1
250
+ }
251
+ return Chunk.drop(chunk, iteratorIndex)
252
+ }
253
+
254
+ slide(): void {
255
+ if (this.subscribersIndex !== this.publisherIndex) {
256
+ const index = this.subscribersIndex % this.capacity
257
+ this.array[index] = null as unknown as A
258
+ this.subscribers[index] = 0
259
+ this.subscribersIndex += 1
260
+ }
261
+ }
262
+
263
+ subscribe(): Subscription<A> {
264
+ this.subscriberCount += 1
265
+ return new BoundedPubSubArbSubscription(this, this.publisherIndex, false)
266
+ }
267
+ }
268
+
269
+ class BoundedPubSubArbSubscription<A> implements Subscription<A> {
270
+ constructor(
271
+ private self: BoundedPubSubArb<A>,
272
+ private subscriberIndex: number,
273
+ private unsubscribed: boolean
274
+ ) {
275
+ }
276
+
277
+ isEmpty(): boolean {
278
+ return (
279
+ this.unsubscribed ||
280
+ this.self.publisherIndex === this.subscriberIndex ||
281
+ this.self.publisherIndex === this.self.subscribersIndex
282
+ )
283
+ }
284
+
285
+ size() {
286
+ if (this.unsubscribed) {
287
+ return 0
288
+ }
289
+ return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex)
290
+ }
291
+
292
+ poll<D>(default_: D): A | D {
293
+ if (this.unsubscribed) {
294
+ return default_
295
+ }
296
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
297
+ if (this.subscriberIndex !== this.self.publisherIndex) {
298
+ const index = this.subscriberIndex % this.self.capacity
299
+ const elem = this.self.array[index]!
300
+ this.self.subscribers[index] -= 1
301
+ if (this.self.subscribers[index] === 0) {
302
+ this.self.array[index] = null as unknown as A
303
+ this.self.subscribersIndex += 1
304
+ }
305
+ this.subscriberIndex += 1
306
+ return elem
307
+ }
308
+ return default_
309
+ }
310
+
311
+ pollUpTo(n: number): Chunk.Chunk<A> {
312
+ if (this.unsubscribed) {
313
+ return Chunk.empty()
314
+ }
315
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
316
+ const size = this.self.publisherIndex - this.subscriberIndex
317
+ const toPoll = Math.min(n, size)
318
+ if (toPoll <= 0) {
319
+ return Chunk.empty()
320
+ }
321
+ const builder: Array<A> = []
322
+ const pollUpToIndex = this.subscriberIndex + toPoll
323
+ while (this.subscriberIndex !== pollUpToIndex) {
324
+ const index = this.subscriberIndex % this.self.capacity
325
+ const a = this.self.array[index] as A
326
+ this.self.subscribers[index] -= 1
327
+ if (this.self.subscribers[index] === 0) {
328
+ this.self.array[index] = null as unknown as A
329
+ this.self.subscribersIndex += 1
330
+ }
331
+ builder.push(a)
332
+ this.subscriberIndex += 1
333
+ }
334
+
335
+ return Chunk.fromIterable(builder)
336
+ }
337
+
338
+ unsubscribe(): void {
339
+ if (!this.unsubscribed) {
340
+ this.unsubscribed = true
341
+ this.self.subscriberCount -= 1
342
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
343
+ while (this.subscriberIndex !== this.self.publisherIndex) {
344
+ const index = this.subscriberIndex % this.self.capacity
345
+ this.self.subscribers[index] -= 1
346
+ if (this.self.subscribers[index] === 0) {
347
+ this.self.array[index] = null as unknown as A
348
+ this.self.subscribersIndex += 1
349
+ }
350
+ this.subscriberIndex += 1
351
+ }
352
+ }
353
+ }
354
+ }
355
+
356
+ /** @internal */
357
+ class BoundedPubSubPow2<A> implements AtomicPubSub<A> {
358
+ array: Array<A>
359
+ mask: number
360
+ publisherIndex = 0
361
+ subscribers: Array<number>
362
+ subscriberCount = 0
363
+ subscribersIndex = 0
364
+
365
+ readonly capacity: number
366
+
367
+ constructor(requestedCapacity: number) {
368
+ this.array = Array.from({ length: requestedCapacity })
369
+ this.mask = requestedCapacity - 1
370
+ this.subscribers = Array.from({ length: requestedCapacity })
371
+ this.capacity = requestedCapacity
372
+ }
373
+
374
+ isEmpty(): boolean {
375
+ return this.publisherIndex === this.subscribersIndex
376
+ }
377
+
378
+ isFull(): boolean {
379
+ return this.publisherIndex === this.subscribersIndex + this.capacity
380
+ }
381
+
382
+ size(): number {
383
+ return this.publisherIndex - this.subscribersIndex
384
+ }
385
+
386
+ publish(value: A): boolean {
387
+ if (this.isFull()) {
388
+ return false
389
+ }
390
+ if (this.subscriberCount !== 0) {
391
+ const index = this.publisherIndex & this.mask
392
+ this.array[index] = value
393
+ this.subscribers[index] = this.subscriberCount
394
+ this.publisherIndex += 1
395
+ }
396
+ return true
397
+ }
398
+
399
+ publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
400
+ const chunk = Chunk.fromIterable(elements)
401
+ const n = chunk.length
402
+ const size = this.publisherIndex - this.subscribersIndex
403
+ const available = this.capacity - size
404
+ const forPubSub = Math.min(n, available)
405
+ if (forPubSub === 0) {
406
+ return chunk
407
+ }
408
+ let iteratorIndex = 0
409
+ const publishAllIndex = this.publisherIndex + forPubSub
410
+ while (this.publisherIndex !== publishAllIndex) {
411
+ const elem = Chunk.unsafeGet(chunk, iteratorIndex++)
412
+ const index = this.publisherIndex & this.mask
413
+ this.array[index] = elem
414
+ this.subscribers[index] = this.subscriberCount
415
+ this.publisherIndex += 1
416
+ }
417
+ return Chunk.drop(chunk, iteratorIndex)
418
+ }
419
+
420
+ slide(): void {
421
+ if (this.subscribersIndex !== this.publisherIndex) {
422
+ const index = this.subscribersIndex & this.mask
423
+ this.array[index] = null as unknown as A
424
+ this.subscribers[index] = 0
425
+ this.subscribersIndex += 1
426
+ }
427
+ }
428
+
429
+ subscribe(): Subscription<A> {
430
+ this.subscriberCount += 1
431
+ return new BoundedPubSubPow2Subscription(this, this.publisherIndex, false)
432
+ }
433
+ }
434
+
435
+ /** @internal */
436
+ class BoundedPubSubPow2Subscription<A> implements Subscription<A> {
437
+ constructor(
438
+ private self: BoundedPubSubPow2<A>,
439
+ private subscriberIndex: number,
440
+ private unsubscribed: boolean
441
+ ) {
442
+ }
443
+
444
+ isEmpty(): boolean {
445
+ return (
446
+ this.unsubscribed ||
447
+ this.self.publisherIndex === this.subscriberIndex ||
448
+ this.self.publisherIndex === this.self.subscribersIndex
449
+ )
450
+ }
451
+
452
+ size() {
453
+ if (this.unsubscribed) {
454
+ return 0
455
+ }
456
+ return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex)
457
+ }
458
+
459
+ poll<D>(default_: D): A | D {
460
+ if (this.unsubscribed) {
461
+ return default_
462
+ }
463
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
464
+ if (this.subscriberIndex !== this.self.publisherIndex) {
465
+ const index = this.subscriberIndex & this.self.mask
466
+ const elem = this.self.array[index]!
467
+ this.self.subscribers[index] -= 1
468
+ if (this.self.subscribers[index] === 0) {
469
+ this.self.array[index] = null as unknown as A
470
+ this.self.subscribersIndex += 1
471
+ }
472
+ this.subscriberIndex += 1
473
+ return elem
474
+ }
475
+ return default_
476
+ }
477
+
478
+ pollUpTo(n: number): Chunk.Chunk<A> {
479
+ if (this.unsubscribed) {
480
+ return Chunk.empty()
481
+ }
482
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
483
+ const size = this.self.publisherIndex - this.subscriberIndex
484
+ const toPoll = Math.min(n, size)
485
+ if (toPoll <= 0) {
486
+ return Chunk.empty()
487
+ }
488
+ const builder: Array<A> = []
489
+ const pollUpToIndex = this.subscriberIndex + toPoll
490
+ while (this.subscriberIndex !== pollUpToIndex) {
491
+ const index = this.subscriberIndex & this.self.mask
492
+ const elem = this.self.array[index] as A
493
+ this.self.subscribers[index] -= 1
494
+ if (this.self.subscribers[index] === 0) {
495
+ this.self.array[index] = null as unknown as A
496
+ this.self.subscribersIndex += 1
497
+ }
498
+ builder.push(elem)
499
+ this.subscriberIndex += 1
500
+ }
501
+ return Chunk.fromIterable(builder)
502
+ }
503
+
504
+ unsubscribe(): void {
505
+ if (!this.unsubscribed) {
506
+ this.unsubscribed = true
507
+ this.self.subscriberCount -= 1
508
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
509
+ while (this.subscriberIndex !== this.self.publisherIndex) {
510
+ const index = this.subscriberIndex & this.self.mask
511
+ this.self.subscribers[index] -= 1
512
+ if (this.self.subscribers[index] === 0) {
513
+ this.self.array[index] = null as unknown as A
514
+ this.self.subscribersIndex += 1
515
+ }
516
+ this.subscriberIndex += 1
517
+ }
518
+ }
519
+ }
520
+ }
521
+
522
+ /** @internal */
523
+ class BoundedPubSubSingle<A> implements AtomicPubSub<A> {
524
+ publisherIndex = 0
525
+ subscriberCount = 0
526
+ subscribers = 0
527
+ value: A = null as unknown as A
528
+
529
+ readonly capacity = 1
530
+
531
+ pipe() {
532
+ return pipeArguments(this, arguments)
533
+ }
534
+
535
+ isEmpty(): boolean {
536
+ return this.subscribers === 0
537
+ }
538
+
539
+ isFull(): boolean {
540
+ return !this.isEmpty()
541
+ }
542
+
543
+ size(): number {
544
+ return this.isEmpty() ? 0 : 1
545
+ }
546
+
547
+ publish(value: A): boolean {
548
+ if (this.isFull()) {
549
+ return false
550
+ }
551
+ if (this.subscriberCount !== 0) {
552
+ this.value = value
553
+ this.subscribers = this.subscriberCount
554
+ this.publisherIndex += 1
555
+ }
556
+ return true
557
+ }
558
+
559
+ publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
560
+ const chunk = Chunk.fromIterable(elements)
561
+ if (Chunk.isEmpty(chunk)) {
562
+ return chunk
563
+ }
564
+ if (this.publish(Chunk.unsafeHead(chunk))) {
565
+ return Chunk.drop(chunk, 1)
566
+ } else {
567
+ return chunk
568
+ }
569
+ }
570
+
571
+ slide(): void {
572
+ if (this.isFull()) {
573
+ this.subscribers = 0
574
+ this.value = null as unknown as A
575
+ }
576
+ }
577
+
578
+ subscribe(): Subscription<A> {
579
+ this.subscriberCount += 1
580
+ return new BoundedPubSubSingleSubscription(this, this.publisherIndex, false)
581
+ }
582
+ }
583
+
584
+ /** @internal */
585
+ class BoundedPubSubSingleSubscription<A> implements Subscription<A> {
586
+ constructor(
587
+ private self: BoundedPubSubSingle<A>,
588
+ private subscriberIndex: number,
589
+ private unsubscribed: boolean
590
+ ) {
591
+ }
592
+
593
+ isEmpty(): boolean {
594
+ return (
595
+ this.unsubscribed ||
596
+ this.self.subscribers === 0 ||
597
+ this.subscriberIndex === this.self.publisherIndex
598
+ )
599
+ }
600
+
601
+ size() {
602
+ return this.isEmpty() ? 0 : 1
603
+ }
604
+
605
+ poll<D>(default_: D): A | D {
606
+ if (this.isEmpty()) {
607
+ return default_
608
+ }
609
+ const elem = this.self.value
610
+ this.self.subscribers -= 1
611
+ if (this.self.subscribers === 0) {
612
+ this.self.value = null as unknown as A
613
+ }
614
+ this.subscriberIndex += 1
615
+ return elem
616
+ }
617
+
618
+ pollUpTo(n: number): Chunk.Chunk<A> {
619
+ if (this.isEmpty() || n < 1) {
620
+ return Chunk.empty()
621
+ }
622
+ const a = this.self.value
623
+ this.self.subscribers -= 1
624
+ if (this.self.subscribers === 0) {
625
+ this.self.value = null as unknown as A
626
+ }
627
+ this.subscriberIndex += 1
628
+ return Chunk.of(a)
629
+ }
630
+
631
+ unsubscribe(): void {
632
+ if (!this.unsubscribed) {
633
+ this.unsubscribed = true
634
+ this.self.subscriberCount -= 1
635
+ if (this.subscriberIndex !== this.self.publisherIndex) {
636
+ this.self.subscribers -= 1
637
+ if (this.self.subscribers === 0) {
638
+ this.self.value = null as unknown as A
639
+ }
640
+ }
641
+ }
642
+ }
643
+ }
644
+
645
+ /** @internal */
646
+ class Node<A> {
647
+ constructor(
648
+ public value: A | null,
649
+ public subscribers: number,
650
+ public next: Node<A> | null
651
+ ) {
652
+ }
653
+ }
654
+
655
+ /** @internal */
656
+ class UnboundedPubSub<A> implements AtomicPubSub<A> {
657
+ publisherHead = new Node<A>(null, 0, null)
658
+ publisherIndex = 0
659
+ publisherTail: Node<A>
660
+ subscribersIndex = 0
661
+
662
+ readonly capacity = Number.MAX_SAFE_INTEGER
663
+
664
+ constructor() {
665
+ this.publisherTail = this.publisherHead
666
+ }
667
+
668
+ isEmpty(): boolean {
669
+ return this.publisherHead === this.publisherTail
670
+ }
671
+
672
+ isFull(): boolean {
673
+ return false
674
+ }
675
+
676
+ size(): number {
677
+ return this.publisherIndex - this.subscribersIndex
678
+ }
679
+
680
+ publish(value: A): boolean {
681
+ const subscribers = this.publisherTail.subscribers
682
+ if (subscribers !== 0) {
683
+ this.publisherTail.next = new Node(value, subscribers, null)
684
+ this.publisherTail = this.publisherTail.next
685
+ this.publisherIndex += 1
686
+ }
687
+ return true
688
+ }
689
+
690
+ publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
691
+ for (const a of elements) {
692
+ this.publish(a)
693
+ }
694
+ return Chunk.empty()
695
+ }
696
+
697
+ slide(): void {
698
+ if (this.publisherHead !== this.publisherTail) {
699
+ this.publisherHead = this.publisherHead.next!
700
+ this.publisherHead.value = null
701
+ this.subscribersIndex += 1
702
+ }
703
+ }
704
+
705
+ subscribe(): Subscription<A> {
706
+ this.publisherTail.subscribers += 1
707
+ return new UnboundedPubSubSubscription(
708
+ this,
709
+ this.publisherTail,
710
+ this.publisherIndex,
711
+ false
712
+ )
713
+ }
714
+ }
715
+
716
+ /** @internal */
717
+ class UnboundedPubSubSubscription<A> implements Subscription<A> {
718
+ constructor(
719
+ private self: UnboundedPubSub<A>,
720
+ private subscriberHead: Node<A>,
721
+ private subscriberIndex: number,
722
+ private unsubscribed: boolean
723
+ ) {
724
+ }
725
+
726
+ isEmpty(): boolean {
727
+ if (this.unsubscribed) {
728
+ return true
729
+ }
730
+ let empty = true
731
+ let loop = true
732
+ while (loop) {
733
+ if (this.subscriberHead === this.self.publisherTail) {
734
+ loop = false
735
+ } else {
736
+ if (this.subscriberHead.next!.value !== null) {
737
+ empty = false
738
+ loop = false
739
+ } else {
740
+ this.subscriberHead = this.subscriberHead.next!
741
+ this.subscriberIndex += 1
742
+ }
743
+ }
744
+ }
745
+ return empty
746
+ }
747
+
748
+ size() {
749
+ if (this.unsubscribed) {
750
+ return 0
751
+ }
752
+ return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex)
753
+ }
754
+
755
+ poll<D>(default_: D): A | D {
756
+ if (this.unsubscribed) {
757
+ return default_
758
+ }
759
+ let loop = true
760
+ let polled: A | D = default_
761
+ while (loop) {
762
+ if (this.subscriberHead === this.self.publisherTail) {
763
+ loop = false
764
+ } else {
765
+ const elem = this.subscriberHead.next!.value
766
+ if (elem !== null) {
767
+ polled = elem
768
+ this.subscriberHead.subscribers -= 1
769
+ if (this.subscriberHead.subscribers === 0) {
770
+ this.self.publisherHead = this.self.publisherHead.next!
771
+ this.self.publisherHead.value = null
772
+ this.self.subscribersIndex += 1
773
+ }
774
+ loop = false
775
+ }
776
+ this.subscriberHead = this.subscriberHead.next!
777
+ this.subscriberIndex += 1
778
+ }
779
+ }
780
+ return polled
781
+ }
782
+
783
+ pollUpTo(n: number): Chunk.Chunk<A> {
784
+ const builder: Array<A> = []
785
+ const default_ = null
786
+ let i = 0
787
+ while (i !== n) {
788
+ const a = this.poll(default_ as unknown as A)
789
+ if (a === default_) {
790
+ i = n
791
+ } else {
792
+ builder.push(a)
793
+ i += 1
794
+ }
795
+ }
796
+ return Chunk.fromIterable(builder)
797
+ }
798
+
799
+ unsubscribe(): void {
800
+ if (!this.unsubscribed) {
801
+ this.unsubscribed = true
802
+ this.self.publisherTail.subscribers -= 1
803
+ while (this.subscriberHead !== this.self.publisherTail) {
804
+ if (this.subscriberHead.next!.value !== null) {
805
+ this.subscriberHead.subscribers -= 1
806
+ if (this.subscriberHead.subscribers === 0) {
807
+ this.self.publisherHead = this.self.publisherHead.next!
808
+ this.self.publisherHead.value = null
809
+ this.self.subscribersIndex += 1
810
+ }
811
+ }
812
+ this.subscriberHead = this.subscriberHead.next!
813
+ }
814
+ }
815
+ }
816
+ }
817
+
818
+ /** @internal */
819
+ class SubscriptionImpl<A> implements Queue.Dequeue<A> {
820
+ [queue.DequeueTypeId] = queue.dequeueVariance
821
+
822
+ constructor(
823
+ readonly pubsub: AtomicPubSub<A>,
824
+ readonly subscribers: Subscribers<A>,
825
+ readonly subscription: Subscription<A>,
826
+ readonly pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>,
827
+ readonly shutdownHook: Deferred.Deferred<never, void>,
828
+ readonly shutdownFlag: MutableRef.MutableRef<boolean>,
829
+ readonly strategy: PubSubStrategy<A>
830
+ ) {
831
+ }
832
+
833
+ pipe() {
834
+ return pipeArguments(this, arguments)
835
+ }
836
+
837
+ capacity(): number {
838
+ return this.pubsub.capacity
839
+ }
840
+
841
+ isActive(): boolean {
842
+ return !MutableRef.get(this.shutdownFlag)
843
+ }
844
+
845
+ size(): Effect.Effect<never, never, number> {
846
+ return core.suspend(() =>
847
+ MutableRef.get(this.shutdownFlag)
848
+ ? core.interrupt
849
+ : core.succeed(this.subscription.size())
850
+ )
851
+ }
852
+
853
+ unsafeSize(): Option.Option<number> {
854
+ if (MutableRef.get(this.shutdownFlag)) {
855
+ return Option.none()
856
+ }
857
+ return Option.some(this.subscription.size())
858
+ }
859
+
860
+ isFull(): Effect.Effect<never, never, boolean> {
861
+ return core.map(this.size(), (size) => size === this.capacity())
862
+ }
863
+
864
+ isEmpty(): Effect.Effect<never, never, boolean> {
865
+ return core.map(this.size(), (size) => size === 0)
866
+ }
867
+
868
+ shutdown(): Effect.Effect<never, never, void> {
869
+ return core.uninterruptible(
870
+ core.withFiberRuntime<never, never, void>((state) => {
871
+ MutableRef.set(this.shutdownFlag, true)
872
+ return pipe(
873
+ fiberRuntime.forEachParUnbounded(
874
+ unsafePollAllQueue(this.pollers),
875
+ (d) => core.deferredInterruptWith(d, state.id()),
876
+ false
877
+ ),
878
+ core.zipRight(core.sync(() => {
879
+ this.subscribers.delete(this.subscription)
880
+ this.subscription.unsubscribe()
881
+ this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers)
882
+ })),
883
+ core.whenEffect(core.deferredSucceed(this.shutdownHook, void 0)),
884
+ core.asUnit
885
+ )
886
+ })
887
+ )
888
+ }
889
+
890
+ isShutdown(): Effect.Effect<never, never, boolean> {
891
+ return core.sync(() => MutableRef.get(this.shutdownFlag))
892
+ }
893
+
894
+ awaitShutdown(): Effect.Effect<never, never, void> {
895
+ return core.deferredAwait(this.shutdownHook)
896
+ }
897
+
898
+ take(): Effect.Effect<never, never, A> {
899
+ return core.withFiberRuntime<never, never, A>((state) => {
900
+ if (MutableRef.get(this.shutdownFlag)) {
901
+ return core.interrupt
902
+ }
903
+ const message = MutableQueue.isEmpty(this.pollers)
904
+ ? this.subscription.poll(MutableQueue.EmptyMutableQueue)
905
+ : MutableQueue.EmptyMutableQueue
906
+ if (message === MutableQueue.EmptyMutableQueue) {
907
+ const deferred = core.deferredUnsafeMake<never, A>(state.id())
908
+ return pipe(
909
+ core.suspend(() => {
910
+ pipe(this.pollers, MutableQueue.offer(deferred))
911
+ pipe(this.subscribers, addSubscribers(this.subscription, this.pollers))
912
+ this.strategy.unsafeCompletePollers(
913
+ this.pubsub,
914
+ this.subscribers,
915
+ this.subscription,
916
+ this.pollers
917
+ )
918
+ return MutableRef.get(this.shutdownFlag) ? core.interrupt : core.deferredAwait(deferred)
919
+ }),
920
+ core.onInterrupt(() => core.sync(() => unsafeRemove(this.pollers, deferred)))
921
+ )
922
+ } else {
923
+ this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers)
924
+ return core.succeed(message)
925
+ }
926
+ })
927
+ }
928
+
929
+ takeAll(): Effect.Effect<never, never, Chunk.Chunk<A>> {
930
+ return core.suspend(() => {
931
+ if (MutableRef.get(this.shutdownFlag)) {
932
+ return core.interrupt
933
+ }
934
+ const as = MutableQueue.isEmpty(this.pollers)
935
+ ? unsafePollAllSubscription(this.subscription)
936
+ : Chunk.empty()
937
+ this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers)
938
+ return core.succeed(as)
939
+ })
940
+ }
941
+
942
+ takeUpTo(this: this, max: number): Effect.Effect<never, never, Chunk.Chunk<A>> {
943
+ return core.suspend(() => {
944
+ if (MutableRef.get(this.shutdownFlag)) {
945
+ return core.interrupt
946
+ }
947
+ const as = MutableQueue.isEmpty(this.pollers)
948
+ ? unsafePollN(this.subscription, max)
949
+ : Chunk.empty()
950
+ this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers)
951
+ return core.succeed(as)
952
+ })
953
+ }
954
+
955
+ takeBetween(min: number, max: number): Effect.Effect<never, never, Chunk.Chunk<A>> {
956
+ return core.suspend(() => takeRemainderLoop(this, min, max, Chunk.empty()))
957
+ }
958
+ }
959
+
960
+ /** @internal */
961
+ const takeRemainderLoop = <A>(
962
+ self: Queue.Dequeue<A>,
963
+ min: number,
964
+ max: number,
965
+ acc: Chunk.Chunk<A>
966
+ ): Effect.Effect<never, never, Chunk.Chunk<A>> => {
967
+ if (max < min) {
968
+ return core.succeed(acc)
969
+ }
970
+ return pipe(
971
+ self.takeUpTo(max),
972
+ core.flatMap((bs) => {
973
+ const remaining = min - bs.length
974
+ if (remaining === 1) {
975
+ return pipe(self.take(), core.map((b) => pipe(acc, Chunk.appendAll(bs), Chunk.append(b))))
976
+ }
977
+ if (remaining > 1) {
978
+ return pipe(
979
+ self.take(),
980
+ core.flatMap((b) =>
981
+ takeRemainderLoop(
982
+ self,
983
+ remaining - 1,
984
+ max - bs.length - 1,
985
+ pipe(acc, Chunk.appendAll(bs), Chunk.append(b))
986
+ )
987
+ )
988
+ )
989
+ }
990
+ return core.succeed(pipe(acc, Chunk.appendAll(bs)))
991
+ })
992
+ )
993
+ }
994
+
995
+ /** @internal */
996
+ class PubSubImpl<A> implements PubSub.PubSub<A> {
997
+ readonly [queue.EnqueueTypeId] = queue.enqueueVariance
998
+
999
+ constructor(
1000
+ readonly pubsub: AtomicPubSub<A>,
1001
+ readonly subscribers: Subscribers<A>,
1002
+ readonly scope: Scope.Scope.Closeable,
1003
+ readonly shutdownHook: Deferred.Deferred<never, void>,
1004
+ readonly shutdownFlag: MutableRef.MutableRef<boolean>,
1005
+ readonly strategy: PubSubStrategy<A>
1006
+ ) {
1007
+ }
1008
+
1009
+ capacity(): number {
1010
+ return this.pubsub.capacity
1011
+ }
1012
+
1013
+ size(): Effect.Effect<never, never, number> {
1014
+ return core.suspend(() =>
1015
+ MutableRef.get(this.shutdownFlag) ?
1016
+ core.interrupt :
1017
+ core.sync(() => this.pubsub.size())
1018
+ )
1019
+ }
1020
+
1021
+ unsafeSize(): Option.Option<number> {
1022
+ if (MutableRef.get(this.shutdownFlag)) {
1023
+ return Option.none()
1024
+ }
1025
+ return Option.some(this.pubsub.size())
1026
+ }
1027
+
1028
+ isFull(): Effect.Effect<never, never, boolean> {
1029
+ return core.map(this.size(), (size) => size === this.capacity())
1030
+ }
1031
+
1032
+ isEmpty(): Effect.Effect<never, never, boolean> {
1033
+ return core.map(this.size(), (size) => size === 0)
1034
+ }
1035
+
1036
+ awaitShutdown(): Effect.Effect<never, never, void> {
1037
+ return core.deferredAwait(this.shutdownHook)
1038
+ }
1039
+
1040
+ isShutdown(): Effect.Effect<never, never, boolean> {
1041
+ return core.sync(() => MutableRef.get(this.shutdownFlag))
1042
+ }
1043
+
1044
+ shutdown(): Effect.Effect<never, never, void> {
1045
+ return core.uninterruptible(core.withFiberRuntime<never, never, void>((state) => {
1046
+ pipe(this.shutdownFlag, MutableRef.set(true))
1047
+ return pipe(
1048
+ this.scope.close(core.exitInterrupt(state.id())),
1049
+ core.zipRight(this.strategy.shutdown()),
1050
+ core.whenEffect(core.deferredSucceed(this.shutdownHook, void 0)),
1051
+ core.asUnit
1052
+ )
1053
+ }))
1054
+ }
1055
+
1056
+ publish(value: A): Effect.Effect<never, never, boolean> {
1057
+ return core.suspend(() => {
1058
+ if (MutableRef.get(this.shutdownFlag)) {
1059
+ return core.interrupt
1060
+ }
1061
+
1062
+ if ((this.pubsub as AtomicPubSub<unknown>).publish(value)) {
1063
+ this.strategy.unsafeCompleteSubscribers(this.pubsub, this.subscribers)
1064
+ return core.succeed(true)
1065
+ }
1066
+
1067
+ return this.strategy.handleSurplus(
1068
+ this.pubsub,
1069
+ this.subscribers,
1070
+ Chunk.of(value),
1071
+ this.shutdownFlag
1072
+ )
1073
+ })
1074
+ }
1075
+
1076
+ isActive(): boolean {
1077
+ return !MutableRef.get(this.shutdownFlag)
1078
+ }
1079
+
1080
+ unsafeOffer(value: A): boolean {
1081
+ if (MutableRef.get(this.shutdownFlag)) {
1082
+ return false
1083
+ }
1084
+
1085
+ if ((this.pubsub as AtomicPubSub<unknown>).publish(value)) {
1086
+ this.strategy.unsafeCompleteSubscribers(this.pubsub, this.subscribers)
1087
+ return true
1088
+ }
1089
+
1090
+ return false
1091
+ }
1092
+
1093
+ publishAll(elements: Iterable<A>): Effect.Effect<never, never, boolean> {
1094
+ return core.suspend(() => {
1095
+ if (MutableRef.get(this.shutdownFlag)) {
1096
+ return core.interrupt
1097
+ }
1098
+ const surplus = unsafePublishAll(this.pubsub, elements)
1099
+ this.strategy.unsafeCompleteSubscribers(this.pubsub, this.subscribers)
1100
+ if (Chunk.isEmpty(surplus)) {
1101
+ return core.succeed(true)
1102
+ }
1103
+ return this.strategy.handleSurplus(
1104
+ this.pubsub,
1105
+ this.subscribers,
1106
+ surplus,
1107
+ this.shutdownFlag
1108
+ )
1109
+ })
1110
+ }
1111
+
1112
+ subscribe(): Effect.Effect<Scope.Scope, never, Queue.Dequeue<A>> {
1113
+ const acquire = core.tap(
1114
+ fiberRuntime.all([
1115
+ this.scope.fork(executionStrategy.sequential),
1116
+ makeSubscription(this.pubsub, this.subscribers, this.strategy)
1117
+ ]),
1118
+ (tuple) => tuple[0].addFinalizer(() => tuple[1].shutdown())
1119
+ )
1120
+ return core.map(
1121
+ fiberRuntime.acquireRelease(acquire, (tuple, exit) => tuple[0].close(exit)),
1122
+ (tuple) => tuple[1]
1123
+ )
1124
+ }
1125
+
1126
+ offer(value: A): Effect.Effect<never, never, boolean> {
1127
+ return this.publish(value)
1128
+ }
1129
+
1130
+ offerAll(elements: Iterable<A>): Effect.Effect<never, never, boolean> {
1131
+ return this.publishAll(elements)
1132
+ }
1133
+
1134
+ pipe() {
1135
+ return pipeArguments(this, arguments)
1136
+ }
1137
+ }
1138
+
1139
+ /** @internal */
1140
+ export const makePubSub = <A>(
1141
+ pubsub: AtomicPubSub<A>,
1142
+ strategy: PubSubStrategy<A>
1143
+ ): Effect.Effect<never, never, PubSub.PubSub<A>> =>
1144
+ core.flatMap(
1145
+ fiberRuntime.scopeMake(),
1146
+ (scope) =>
1147
+ core.map(core.deferredMake<never, void>(), (deferred) =>
1148
+ unsafeMakePubSub(
1149
+ pubsub,
1150
+ new Map(),
1151
+ scope,
1152
+ deferred,
1153
+ MutableRef.make(false),
1154
+ strategy
1155
+ ))
1156
+ )
1157
+
1158
+ /** @internal */
1159
+ export const unsafeMakePubSub = <A>(
1160
+ pubsub: AtomicPubSub<A>,
1161
+ subscribers: Subscribers<A>,
1162
+ scope: Scope.Scope.Closeable,
1163
+ shutdownHook: Deferred.Deferred<never, void>,
1164
+ shutdownFlag: MutableRef.MutableRef<boolean>,
1165
+ strategy: PubSubStrategy<A>
1166
+ ): PubSub.PubSub<A> => {
1167
+ return new PubSubImpl(pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy)
1168
+ }
1169
+
1170
+ /** @internal */
1171
+ const nextPow2 = (n: number): number => {
1172
+ const nextPow = Math.ceil(Math.log(n) / Math.log(2.0))
1173
+ return Math.max(Math.pow(2, nextPow), 2)
1174
+ }
1175
+
1176
+ /** @internal */
1177
+ const ensureCapacity = (capacity: number): void => {
1178
+ if (capacity <= 0) {
1179
+ throw cause.InvalidPubSubCapacityException(`Cannot construct PubSub with capacity of ${capacity}`)
1180
+ }
1181
+ }
1182
+
1183
+ /** @internal */
1184
+ const unsafeCompleteDeferred = <A>(deferred: Deferred.Deferred<never, A>, a: A): void => {
1185
+ core.deferredUnsafeDone(deferred, core.succeed(a))
1186
+ }
1187
+
1188
+ /** @internal */
1189
+ const unsafeOfferAll = <A>(queue: MutableQueue.MutableQueue<A>, as: Iterable<A>): Chunk.Chunk<A> => {
1190
+ return pipe(queue, MutableQueue.offerAll(as))
1191
+ }
1192
+
1193
+ /** @internal */
1194
+ const unsafePollAllQueue = <A>(queue: MutableQueue.MutableQueue<A>): Chunk.Chunk<A> => {
1195
+ return pipe(queue, MutableQueue.pollUpTo(Number.POSITIVE_INFINITY))
1196
+ }
1197
+
1198
+ /** @internal */
1199
+ const unsafePollAllSubscription = <A>(subscription: Subscription<A>): Chunk.Chunk<A> => {
1200
+ return subscription.pollUpTo(Number.POSITIVE_INFINITY)
1201
+ }
1202
+
1203
+ /** @internal */
1204
+ const unsafePollN = <A>(subscription: Subscription<A>, max: number): Chunk.Chunk<A> => {
1205
+ return subscription.pollUpTo(max)
1206
+ }
1207
+
1208
+ /** @internal */
1209
+ const unsafePublishAll = <A>(pubsub: AtomicPubSub<A>, as: Iterable<A>): Chunk.Chunk<A> => {
1210
+ return pubsub.publishAll(as)
1211
+ }
1212
+
1213
+ /** @internal */
1214
+ const unsafeRemove = <A>(queue: MutableQueue.MutableQueue<A>, value: A): void => {
1215
+ unsafeOfferAll(
1216
+ queue,
1217
+ pipe(unsafePollAllQueue(queue), Chunk.filter((elem) => elem !== value))
1218
+ )
1219
+ }
1220
+
1221
+ // -----------------------------------------------------------------------------
1222
+ // PubSub.Strategy
1223
+ // -----------------------------------------------------------------------------
1224
+
1225
+ /**
1226
+ * A `PubSubStrategy<A>` describes the protocol for how publishers and subscribers
1227
+ * will communicate with each other through the `PubSub`.
1228
+ *
1229
+ * @internal
1230
+ */
1231
+ export interface PubSubStrategy<A> {
1232
+ /**
1233
+ * Describes any finalization logic associated with this strategy.
1234
+ */
1235
+ shutdown(): Effect.Effect<never, never, void>
1236
+
1237
+ /**
1238
+ * Describes how publishers should signal to subscribers that they are
1239
+ * waiting for space to become available in the `PubSub`.
1240
+ */
1241
+ handleSurplus(
1242
+ pubsub: AtomicPubSub<A>,
1243
+ subscribers: Subscribers<A>,
1244
+ elements: Iterable<A>,
1245
+ isShutdown: MutableRef.MutableRef<boolean>
1246
+ ): Effect.Effect<never, never, boolean>
1247
+
1248
+ /**
1249
+ * Describes how subscribers should signal to publishers waiting for space
1250
+ * to become available in the `PubSub` that space may be available.
1251
+ */
1252
+ unsafeOnPubSubEmptySpace(
1253
+ pubsub: AtomicPubSub<A>,
1254
+ subscribers: Subscribers<A>
1255
+ ): void
1256
+
1257
+ /**
1258
+ * Describes how subscribers waiting for additional values from the `PubSub`
1259
+ * should take those values and signal to publishers that they are no
1260
+ * longer waiting for additional values.
1261
+ */
1262
+ unsafeCompletePollers(
1263
+ pubsub: AtomicPubSub<A>,
1264
+ subscribers: Subscribers<A>,
1265
+ subscription: Subscription<A>,
1266
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
1267
+ ): void
1268
+
1269
+ /**
1270
+ * Describes how publishers should signal to subscribers waiting for
1271
+ * additional values from the `PubSub` that new values are available.
1272
+ */
1273
+ unsafeCompleteSubscribers(
1274
+ pubsub: AtomicPubSub<A>,
1275
+ subscribers: Subscribers<A>
1276
+ ): void
1277
+ }
1278
+
1279
+ /**
1280
+ * A strategy that applies back pressure to publishers when the `PubSub` is at
1281
+ * capacity. This guarantees that all subscribers will receive all messages
1282
+ * published to the `PubSub` while they are subscribed. However, it creates the
1283
+ * risk that a slow subscriber will slow down the rate at which messages
1284
+ * are published and received by other subscribers.
1285
+ *
1286
+ * @internal
1287
+ */
1288
+ class BackPressureStrategy<A> implements PubSubStrategy<A> {
1289
+ publishers: MutableQueue.MutableQueue<
1290
+ readonly [
1291
+ A,
1292
+ Deferred.Deferred<never, boolean>,
1293
+ boolean
1294
+ ]
1295
+ > = MutableQueue.unbounded()
1296
+
1297
+ shutdown(): Effect.Effect<never, never, void> {
1298
+ return core.flatMap(core.fiberId, (fiberId) =>
1299
+ core.flatMap(
1300
+ core.sync(() => unsafePollAllQueue(this.publishers)),
1301
+ (publishers) =>
1302
+ fiberRuntime.forEachParUnboundedDiscard(
1303
+ publishers,
1304
+ ([_, deferred, last]) =>
1305
+ last ?
1306
+ pipe(core.deferredInterruptWith(deferred, fiberId), core.asUnit) :
1307
+ core.unit,
1308
+ false
1309
+ )
1310
+ ))
1311
+ }
1312
+
1313
+ handleSurplus(
1314
+ pubsub: AtomicPubSub<A>,
1315
+ subscribers: Subscribers<A>,
1316
+ elements: Iterable<A>,
1317
+ isShutdown: MutableRef.MutableRef<boolean>
1318
+ ): Effect.Effect<never, never, boolean> {
1319
+ return core.withFiberRuntime<never, never, boolean>((state) => {
1320
+ const deferred = core.deferredUnsafeMake<never, boolean>(state.id())
1321
+ return pipe(
1322
+ core.suspend(() => {
1323
+ this.unsafeOffer(elements, deferred)
1324
+ this.unsafeOnPubSubEmptySpace(pubsub, subscribers)
1325
+ this.unsafeCompleteSubscribers(pubsub, subscribers)
1326
+ return MutableRef.get(isShutdown) ?
1327
+ core.interrupt :
1328
+ core.deferredAwait(deferred)
1329
+ }),
1330
+ core.onInterrupt(() => core.sync(() => this.unsafeRemove(deferred)))
1331
+ )
1332
+ })
1333
+ }
1334
+
1335
+ unsafeOnPubSubEmptySpace(
1336
+ pubsub: AtomicPubSub<A>,
1337
+ subscribers: Subscribers<A>
1338
+ ): void {
1339
+ let keepPolling = true
1340
+ while (keepPolling && !pubsub.isFull()) {
1341
+ const publisher = pipe(this.publishers, MutableQueue.poll(MutableQueue.EmptyMutableQueue))
1342
+ if (publisher === MutableQueue.EmptyMutableQueue) {
1343
+ keepPolling = false
1344
+ } else {
1345
+ const published = pubsub.publish(publisher[0])
1346
+ if (published && publisher[2]) {
1347
+ unsafeCompleteDeferred(publisher[1], true)
1348
+ } else if (!published) {
1349
+ unsafeOfferAll(
1350
+ this.publishers,
1351
+ pipe(unsafePollAllQueue(this.publishers), Chunk.prepend(publisher))
1352
+ )
1353
+ }
1354
+ this.unsafeCompleteSubscribers(pubsub, subscribers)
1355
+ }
1356
+ }
1357
+ }
1358
+
1359
+ unsafeCompletePollers(
1360
+ pubsub: AtomicPubSub<A>,
1361
+ subscribers: Subscribers<A>,
1362
+ subscription: Subscription<A>,
1363
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
1364
+ ): void {
1365
+ return unsafeStrategyCompletePollers(this, pubsub, subscribers, subscription, pollers)
1366
+ }
1367
+
1368
+ unsafeCompleteSubscribers(pubsub: AtomicPubSub<A>, subscribers: Subscribers<A>): void {
1369
+ return unsafeStrategyCompleteSubscribers(this, pubsub, subscribers)
1370
+ }
1371
+
1372
+ private unsafeOffer(elements: Iterable<A>, deferred: Deferred.Deferred<never, boolean>): void {
1373
+ const iterator = elements[Symbol.iterator]()
1374
+ let next: IteratorResult<A> = iterator.next()
1375
+ if (!next.done) {
1376
+ // eslint-disable-next-line no-constant-condition
1377
+ while (1) {
1378
+ const value = next.value
1379
+ next = iterator.next()
1380
+ if (next.done) {
1381
+ pipe(
1382
+ this.publishers,
1383
+ MutableQueue.offer([value, deferred, true as boolean] as const)
1384
+ )
1385
+ break
1386
+ }
1387
+ pipe(
1388
+ this.publishers,
1389
+ MutableQueue.offer([value, deferred, false as boolean] as const)
1390
+ )
1391
+ }
1392
+ }
1393
+ }
1394
+
1395
+ unsafeRemove(deferred: Deferred.Deferred<never, boolean>): void {
1396
+ unsafeOfferAll(
1397
+ this.publishers,
1398
+ pipe(unsafePollAllQueue(this.publishers), Chunk.filter(([_, a]) => a !== deferred))
1399
+ )
1400
+ }
1401
+ }
1402
+
1403
+ /**
1404
+ * A strategy that drops new messages when the `PubSub` is at capacity. This
1405
+ * guarantees that a slow subscriber will not slow down the rate at which
1406
+ * messages are published. However, it creates the risk that a slow
1407
+ * subscriber will slow down the rate at which messages are received by
1408
+ * other subscribers and that subscribers may not receive all messages
1409
+ * published to the `PubSub` while they are subscribed.
1410
+ *
1411
+ * @internal
1412
+ */
1413
+ export class DroppingStrategy<A> implements PubSubStrategy<A> {
1414
+ shutdown(): Effect.Effect<never, never, void> {
1415
+ return core.unit
1416
+ }
1417
+
1418
+ handleSurplus(
1419
+ _pubsub: AtomicPubSub<A>,
1420
+ _subscribers: Subscribers<A>,
1421
+ _elements: Iterable<A>,
1422
+ _isShutdown: MutableRef.MutableRef<boolean>
1423
+ ): Effect.Effect<never, never, boolean> {
1424
+ return core.succeed(false)
1425
+ }
1426
+
1427
+ unsafeOnPubSubEmptySpace(
1428
+ _pubsub: AtomicPubSub<A>,
1429
+ _subscribers: Subscribers<A>
1430
+ ): void {
1431
+ //
1432
+ }
1433
+
1434
+ unsafeCompletePollers(
1435
+ pubsub: AtomicPubSub<A>,
1436
+ subscribers: Subscribers<A>,
1437
+ subscription: Subscription<A>,
1438
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
1439
+ ): void {
1440
+ return unsafeStrategyCompletePollers(this, pubsub, subscribers, subscription, pollers)
1441
+ }
1442
+
1443
+ unsafeCompleteSubscribers(pubsub: AtomicPubSub<A>, subscribers: Subscribers<A>): void {
1444
+ return unsafeStrategyCompleteSubscribers(this, pubsub, subscribers)
1445
+ }
1446
+ }
1447
+
1448
+ /**
1449
+ * A strategy that adds new messages and drops old messages when the `PubSub` is
1450
+ * at capacity. This guarantees that a slow subscriber will not slow down
1451
+ * the rate at which messages are published and received by other
1452
+ * subscribers. However, it creates the risk that a slow subscriber will
1453
+ * not receive some messages published to the `PubSub` while it is subscribed.
1454
+ *
1455
+ * @internal
1456
+ */
1457
+ export class SlidingStrategy<A> implements PubSubStrategy<A> {
1458
+ shutdown(): Effect.Effect<never, never, void> {
1459
+ return core.unit
1460
+ }
1461
+
1462
+ handleSurplus(
1463
+ pubsub: AtomicPubSub<A>,
1464
+ subscribers: Subscribers<A>,
1465
+ elements: Iterable<A>,
1466
+ _isShutdown: MutableRef.MutableRef<boolean>
1467
+ ): Effect.Effect<never, never, boolean> {
1468
+ return core.sync(() => {
1469
+ this.unsafeSlidingPublish(pubsub, elements)
1470
+ this.unsafeCompleteSubscribers(pubsub, subscribers)
1471
+ return true
1472
+ })
1473
+ }
1474
+
1475
+ unsafeOnPubSubEmptySpace(
1476
+ _pubsub: AtomicPubSub<A>,
1477
+ _subscribers: Subscribers<A>
1478
+ ): void {
1479
+ //
1480
+ }
1481
+
1482
+ unsafeCompletePollers(
1483
+ pubsub: AtomicPubSub<A>,
1484
+ subscribers: Subscribers<A>,
1485
+ subscription: Subscription<A>,
1486
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
1487
+ ): void {
1488
+ return unsafeStrategyCompletePollers(this, pubsub, subscribers, subscription, pollers)
1489
+ }
1490
+
1491
+ unsafeCompleteSubscribers(pubsub: AtomicPubSub<A>, subscribers: Subscribers<A>): void {
1492
+ return unsafeStrategyCompleteSubscribers(this, pubsub, subscribers)
1493
+ }
1494
+
1495
+ unsafeSlidingPublish(pubsub: AtomicPubSub<A>, elements: Iterable<A>): void {
1496
+ const it = elements[Symbol.iterator]()
1497
+ let next = it.next()
1498
+ if (!next.done && pubsub.capacity > 0) {
1499
+ let a = next.value
1500
+ let loop = true
1501
+ while (loop) {
1502
+ pubsub.slide()
1503
+ const pub = pubsub.publish(a)
1504
+ if (pub && (next = it.next()) && !next.done) {
1505
+ a = next.value
1506
+ } else if (pub) {
1507
+ loop = false
1508
+ }
1509
+ }
1510
+ }
1511
+ }
1512
+ }
1513
+
1514
+ /** @internal */
1515
+ const unsafeStrategyCompletePollers = <A>(
1516
+ strategy: PubSubStrategy<A>,
1517
+ pubsub: AtomicPubSub<A>,
1518
+ subscribers: Subscribers<A>,
1519
+ subscription: Subscription<A>,
1520
+ pollers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
1521
+ ): void => {
1522
+ let keepPolling = true
1523
+ while (keepPolling && !subscription.isEmpty()) {
1524
+ const poller = pipe(pollers, MutableQueue.poll(MutableQueue.EmptyMutableQueue))
1525
+ if (poller === MutableQueue.EmptyMutableQueue) {
1526
+ pipe(subscribers, removeSubscribers(subscription, pollers))
1527
+ if (MutableQueue.isEmpty(pollers)) {
1528
+ keepPolling = false
1529
+ } else {
1530
+ pipe(subscribers, addSubscribers(subscription, pollers))
1531
+ }
1532
+ } else {
1533
+ const pollResult = subscription.poll(MutableQueue.EmptyMutableQueue)
1534
+ if (pollResult === MutableQueue.EmptyMutableQueue) {
1535
+ unsafeOfferAll(pollers, pipe(unsafePollAllQueue(pollers), Chunk.prepend(poller)))
1536
+ } else {
1537
+ unsafeCompleteDeferred(poller, pollResult)
1538
+ strategy.unsafeOnPubSubEmptySpace(pubsub, subscribers)
1539
+ }
1540
+ }
1541
+ }
1542
+ }
1543
+
1544
+ /** @internal */
1545
+ const unsafeStrategyCompleteSubscribers = <A>(
1546
+ strategy: PubSubStrategy<A>,
1547
+ pubsub: AtomicPubSub<A>,
1548
+ subscribers: Subscribers<A>
1549
+ ): void => {
1550
+ for (
1551
+ const [subscription, pollersSet] of subscribers
1552
+ ) {
1553
+ for (const pollers of pollersSet) {
1554
+ strategy.unsafeCompletePollers(pubsub, subscribers, subscription, pollers)
1555
+ }
1556
+ }
1557
+ }