MCPcopy Create free account
hub / github.com/Effect-TS/effect / pump

Function pump

packages/effect/src/Micro.ts:3924–3962  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3922 let pumping = false
3923 let interrupted = false
3924 function pump() {
3925 pumping = true
3926 while (inProgress < concurrency && index < length) {
3927 const currentIndex = index
3928 const item = items[currentIndex]
3929 index++
3930 inProgress++
3931 try {
3932 const child = unsafeFork(parent, f(item, currentIndex), true, true)
3933 fibers.add(child)
3934 child.addObserver((exit) => {
3935 fibers.delete(child)
3936 if (interrupted) {
3937 return
3938 } else if (exit._tag === "Failure") {
3939 if (result === undefined) {
3940 result = exit
3941 length = index
3942 fibers.forEach((fiber) => fiber.unsafeInterrupt())
3943 }
3944 } else if (out !== undefined) {
3945 out[currentIndex] = exit.value
3946 }
3947 doneCount++
3948 inProgress--
3949 if (doneCount === length) {
3950 resume(result ?? succeed(out))
3951 } else if (!pumping && inProgress < concurrency) {
3952 pump()
3953 }
3954 })
3955 } catch (err) {
3956 result = exitDie(err)
3957 length = index
3958 fibers.forEach((fiber) => fiber.unsafeInterrupt())
3959 }
3960 }
3961 pumping = false
3962 }
3963 pump()
3964
3965 return suspend(() => {

Callers 1

forEachFunction · 0.85

Calls 8

unsafeInterruptMethod · 0.80
unsafeForkFunction · 0.70
fFunction · 0.70
resumeFunction · 0.70
exitDieFunction · 0.70
addMethod · 0.65
addObserverMethod · 0.65
succeedFunction · 0.50

Tested by

no test coverage detected