effect 2.4.14 → 2.4.15

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.
@@ -2028,7 +2028,7 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
2028
2028
  }
2029
2029
  return exits
2030
2030
  }
2031
- const runFiber = <A, E, R>(eff: Effect.Effect<A, E, R>) => {
2031
+ const runFiber = <A, E, R>(eff: Effect.Effect<A, E, R>, interruptImmediately = false) => {
2032
2032
  const runnable = core.uninterruptible(graft(eff))
2033
2033
  const fiber = unsafeForkUnstarted(
2034
2034
  runnable,
@@ -2037,6 +2037,9 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
2037
2037
  fiberScope.globalScope
2038
2038
  )
2039
2039
  parent._scheduler.scheduleTask(() => {
2040
+ if (interruptImmediately) {
2041
+ fiber.unsafeInterruptAsFork(parent.id())
2042
+ }
2040
2043
  fiber.resume(runnable)
2041
2044
  }, 0)
2042
2045
  return fiber
@@ -2142,26 +2145,44 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
2142
2145
  }
2143
2146
  })
2144
2147
  )
2145
- return core.asUnit(core.tap(
2146
- core.flatten(core.onInterrupt(
2147
- restore(internalFiber.join(processingFiber)),
2148
- () => {
2149
- onInterruptSignal()
2150
- const all = [processingFiber] as Array<FiberRuntime<any, any>>
2151
- residual.map((blocked) => {
2152
- const fiber = runFiber(blocked)
2153
- parent._scheduler.scheduleTask(() => {
2154
- fiber.unsafeInterruptAsFork(parent.id())
2155
- }, 0)
2156
- return fiber
2157
- }).forEach((additional) => {
2158
- all.push(additional as unknown as FiberRuntime<any, any>)
2159
- })
2160
- return core.exit(fiberJoinAll(all))
2161
- }
2162
- )),
2163
- () => core.forEachSequential(joinOrder, (f) => f.inheritAll)
2164
- ))
2148
+ return core.asUnit(
2149
+ core.onExit(
2150
+ core.flatten(restore(internalFiber.join(processingFiber))),
2151
+ core.exitMatch({
2152
+ onFailure: () => {
2153
+ onInterruptSignal()
2154
+ const target = residual.length + 1
2155
+ const concurrency = Math.min(typeof n === "number" ? n : residual.length, residual.length)
2156
+ const toPop = Array.from(residual)
2157
+ return core.async<any, any>((cb) => {
2158
+ const exits: Array<Exit.Exit<any, any>> = []
2159
+ let count = 0
2160
+ let index = 0
2161
+ const check = (index: number, hitNext: boolean) => (exit: Exit.Exit<any, any>) => {
2162
+ exits[index] = exit
2163
+ count++
2164
+ if (count === target) {
2165
+ cb(Option.getOrThrow(core.exitCollectAll(exits, { parallel: true })))
2166
+ }
2167
+ if (toPop.length > 0 && hitNext) {
2168
+ next()
2169
+ }
2170
+ }
2171
+ const next = () => {
2172
+ runFiber(toPop.pop()!, true).addObserver(check(index, true))
2173
+ index++
2174
+ }
2175
+ processingFiber.addObserver(check(index, false))
2176
+ index++
2177
+ for (let i = 0; i < concurrency; i++) {
2178
+ next()
2179
+ }
2180
+ }) as any
2181
+ },
2182
+ onSuccess: () => core.forEachSequential(joinOrder, (f) => f.inheritAll)
2183
+ })
2184
+ )
2185
+ )
2165
2186
  })
2166
2187
  )
2167
2188
  )
@@ -1,4 +1,4 @@
1
- let moduleVersion = "2.4.14"
1
+ let moduleVersion = "2.4.15"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4