effect 3.21.5 → 3.22.1

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 (63) hide show
  1. package/dist/cjs/Context.js +1 -1
  2. package/dist/cjs/Graph.js +123 -66
  3. package/dist/cjs/Graph.js.map +1 -1
  4. package/dist/cjs/Mailbox.js +3 -2
  5. package/dist/cjs/Mailbox.js.map +1 -1
  6. package/dist/cjs/ParseResult.js +18 -0
  7. package/dist/cjs/ParseResult.js.map +1 -1
  8. package/dist/cjs/internal/config.js +5 -1
  9. package/dist/cjs/internal/config.js.map +1 -1
  10. package/dist/cjs/internal/configProvider.js +14 -1
  11. package/dist/cjs/internal/configProvider.js.map +1 -1
  12. package/dist/cjs/internal/effect/circular.js +5 -4
  13. package/dist/cjs/internal/effect/circular.js.map +1 -1
  14. package/dist/cjs/internal/mailbox.js +11 -19
  15. package/dist/cjs/internal/mailbox.js.map +1 -1
  16. package/dist/cjs/internal/opCodes/config.js +3 -1
  17. package/dist/cjs/internal/opCodes/config.js.map +1 -1
  18. package/dist/cjs/internal/stream/emit.js +6 -34
  19. package/dist/cjs/internal/stream/emit.js.map +1 -1
  20. package/dist/cjs/internal/stream.js +26 -16
  21. package/dist/cjs/internal/stream.js.map +1 -1
  22. package/dist/cjs/internal/version.js +1 -1
  23. package/dist/dts/Context.d.ts +1 -1
  24. package/dist/dts/Graph.d.ts +22 -3
  25. package/dist/dts/Graph.d.ts.map +1 -1
  26. package/dist/dts/Mailbox.d.ts.map +1 -1
  27. package/dist/dts/ParseResult.d.ts.map +1 -1
  28. package/dist/dts/internal/stream.d.ts.map +1 -1
  29. package/dist/esm/Context.js +1 -1
  30. package/dist/esm/Graph.js +116 -61
  31. package/dist/esm/Graph.js.map +1 -1
  32. package/dist/esm/Mailbox.js +3 -2
  33. package/dist/esm/Mailbox.js.map +1 -1
  34. package/dist/esm/ParseResult.js +18 -0
  35. package/dist/esm/ParseResult.js.map +1 -1
  36. package/dist/esm/internal/config.js +5 -1
  37. package/dist/esm/internal/config.js.map +1 -1
  38. package/dist/esm/internal/configProvider.js +14 -1
  39. package/dist/esm/internal/configProvider.js.map +1 -1
  40. package/dist/esm/internal/effect/circular.js +5 -4
  41. package/dist/esm/internal/effect/circular.js.map +1 -1
  42. package/dist/esm/internal/mailbox.js +10 -17
  43. package/dist/esm/internal/mailbox.js.map +1 -1
  44. package/dist/esm/internal/opCodes/config.js +2 -0
  45. package/dist/esm/internal/opCodes/config.js.map +1 -1
  46. package/dist/esm/internal/stream/emit.js +6 -34
  47. package/dist/esm/internal/stream/emit.js.map +1 -1
  48. package/dist/esm/internal/stream.js +22 -13
  49. package/dist/esm/internal/stream.js.map +1 -1
  50. package/dist/esm/internal/version.js +1 -1
  51. package/package.json +1 -1
  52. package/src/Context.ts +1 -1
  53. package/src/Graph.ts +149 -77
  54. package/src/Mailbox.ts +3 -2
  55. package/src/ParseResult.ts +18 -0
  56. package/src/internal/config.ts +14 -1
  57. package/src/internal/configProvider.ts +24 -1
  58. package/src/internal/effect/circular.ts +5 -4
  59. package/src/internal/mailbox.ts +13 -52
  60. package/src/internal/opCodes/config.ts +6 -0
  61. package/src/internal/stream/emit.ts +7 -39
  62. package/src/internal/stream.ts +62 -24
  63. package/src/internal/version.ts +1 -1
@@ -3,9 +3,8 @@ import * as Chunk from "../../Chunk.js"
3
3
  import * as Effect from "../../Effect.js"
4
4
  import * as Exit from "../../Exit.js"
5
5
  import { pipe } from "../../Function.js"
6
+ import type * as Mailbox from "../../Mailbox.js"
6
7
  import * as Option from "../../Option.js"
7
- import type * as Queue from "../../Queue.js"
8
- import type * as Scheduler from "../../Scheduler.js"
9
8
  import type * as Emit from "../../StreamEmit.js"
10
9
 
11
10
  /** @internal */
@@ -48,53 +47,23 @@ export const make = <R, E, A, B>(
48
47
  }
49
48
 
50
49
  /** @internal */
51
- export const makePush = <E, A>(
52
- queue: Queue.Queue<Array<A> | Exit.Exit<void, E>>,
53
- scheduler: Scheduler.Scheduler
54
- ): Emit.EmitOpsPush<E, A> => {
50
+ export const makePush = <E, A>(mailbox: Mailbox.Mailbox<A, E>): Emit.EmitOpsPush<E, A> => {
55
51
  let finished = false
56
- let buffer: Array<A> = []
57
- let running = false
58
52
  function array(items: ReadonlyArray<A>) {
59
53
  if (finished) return false
60
- if (items.length <= 50_000) {
61
- buffer.push.apply(buffer, items as Array<A>)
62
- } else {
63
- for (let i = 0; i < items.length; i++) {
64
- buffer.push(items[0])
65
- }
66
- }
67
- if (!running) {
68
- running = true
69
- scheduler.scheduleTask(flush, 0)
70
- }
71
- return true
72
- }
73
- function flush() {
74
- running = false
75
- if (buffer.length > 0) {
76
- queue.unsafeOffer(buffer)
77
- buffer = []
78
- }
54
+ return Chunk.isEmpty(mailbox.unsafeOfferAll(items))
79
55
  }
80
56
  function done(exit: Exit.Exit<A, E>) {
81
57
  if (finished) return
82
58
  finished = true
83
59
  if (exit._tag === "Success") {
84
- buffer.push(exit.value)
60
+ mailbox.unsafeOffer(exit.value)
85
61
  }
86
- flush()
87
- queue.unsafeOffer(exit._tag === "Success" ? Exit.void : exit)
62
+ mailbox.unsafeDone(exit._tag === "Success" ? Exit.void : exit)
88
63
  }
89
64
  return {
90
65
  single(value: A) {
91
- if (finished) return false
92
- buffer.push(value)
93
- if (!running) {
94
- running = true
95
- scheduler.scheduleTask(flush, 0)
96
- }
97
- return true
66
+ return finished ? false : mailbox.unsafeOffer(value)
98
67
  },
99
68
  array,
100
69
  chunk(chunk) {
@@ -104,8 +73,7 @@ export const makePush = <E, A>(
104
73
  end() {
105
74
  if (finished) return
106
75
  finished = true
107
- flush()
108
- queue.unsafeOffer(Exit.void)
76
+ mailbox.unsafeDone(Exit.void)
109
77
  },
110
78
  halt(cause: Cause.Cause<E>) {
111
79
  return done(Exit.failCause(cause))
@@ -11,11 +11,11 @@ import * as Equal from "../Equal.js"
11
11
  import type { ExecutionPlan } from "../ExecutionPlan.js"
12
12
  import * as Exit from "../Exit.js"
13
13
  import * as Fiber from "../Fiber.js"
14
- import * as FiberRef from "../FiberRef.js"
15
14
  import type { LazyArg } from "../Function.js"
16
15
  import { constTrue, dual, identity, pipe } from "../Function.js"
17
16
  import * as internalExecutionPlan from "../internal/executionPlan.js"
18
17
  import * as Layer from "../Layer.js"
18
+ import type * as Mailbox from "../Mailbox.js"
19
19
  import * as MergeDecision from "../MergeDecision.js"
20
20
  import * as Option from "../Option.js"
21
21
  import type * as Order from "../Order.js"
@@ -42,7 +42,11 @@ import * as channel from "./channel.js"
42
42
  import * as channelExecutor from "./channel/channelExecutor.js"
43
43
  import * as MergeStrategy from "./channel/mergeStrategy.js"
44
44
  import * as core from "./core-stream.js"
45
+ import * as effectCore from "./core.js"
45
46
  import * as doNotation from "./doNotation.js"
47
+ import * as circular from "./effect/circular.js"
48
+ import * as fiberRuntime from "./fiberRuntime.js"
49
+ import * as mailbox from "./mailbox.js"
46
50
  import { RingBuffer } from "./ringBuffer.js"
47
51
  import * as InternalSchedule from "./schedule.js"
48
52
  import * as sink_ from "./sink.js"
@@ -592,21 +596,19 @@ export const asyncEffect = <A, E = never, R = never>(
592
596
  fromChannel
593
597
  )
594
598
 
595
- const queueFromBufferOptionsPush = <A, E>(
599
+ const mailboxFromBufferOptionsPush = <A, E>(
596
600
  options?: { readonly bufferSize: "unbounded" } | {
597
601
  readonly bufferSize?: number | undefined
598
602
  readonly strategy?: "dropping" | "sliding" | undefined
599
603
  } | undefined
600
- ): Effect.Effect<Queue.Queue<Array<A> | Exit.Exit<void, E>>> => {
604
+ ): Effect.Effect<Mailbox.Mailbox<A, E>> => {
601
605
  if (options?.bufferSize === "unbounded" || (options?.bufferSize === undefined && options?.strategy === undefined)) {
602
- return Queue.unbounded()
603
- }
604
- switch (options?.strategy) {
605
- case "sliding":
606
- return Queue.sliding(options.bufferSize ?? 16)
607
- default:
608
- return Queue.dropping(options?.bufferSize ?? 16)
606
+ return mailbox.make()
609
607
  }
608
+ return mailbox.make({
609
+ capacity: options?.bufferSize ?? 16,
610
+ strategy: options?.strategy ?? "dropping"
611
+ })
610
612
  }
611
613
 
612
614
  /** @internal */
@@ -620,21 +622,12 @@ export const asyncPush = <A, E = never, R = never>(
620
622
  } | undefined
621
623
  ): Stream.Stream<A, E, Exclude<R, Scope.Scope>> =>
622
624
  Effect.acquireRelease(
623
- queueFromBufferOptionsPush<A, E>(options),
624
- Queue.shutdown
625
+ mailboxFromBufferOptionsPush<A, E>(options),
626
+ (mailbox) => mailbox.shutdown
625
627
  ).pipe(
626
- Effect.tap((queue) =>
627
- FiberRef.getWith(FiberRef.currentScheduler, (scheduler) => register(emit.makePush(queue, scheduler)))
628
- ),
629
- Effect.map((queue) => {
630
- const loop: Channel.Channel<Chunk.Chunk<A>, unknown, E> = core.flatMap(Queue.take(queue), (item) =>
631
- Exit.isExit(item)
632
- ? Exit.isSuccess(item) ? core.void : core.failCause(item.cause)
633
- : channel.zipRight(core.write(Chunk.unsafeFromArray(item)), loop))
634
- return loop
635
- }),
636
- channel.unwrapScoped,
637
- fromChannel
628
+ Effect.tap((mailbox) => register(emit.makePush(mailbox))),
629
+ Effect.map(mailboxToStream),
630
+ unwrapScoped
638
631
  )
639
632
 
640
633
  /** @internal */
@@ -3011,6 +3004,51 @@ export const toChannel = <A, E, R>(
3011
3004
  }
3012
3005
  }
3013
3006
 
3007
+ /** @internal */
3008
+ export const mailboxToStream = <A, E>(self: Mailbox.ReadonlyMailbox<A, E>): Stream.Stream<A, E> =>
3009
+ fromChannel(mailbox.toChannel(self))
3010
+
3011
+ /** @internal */
3012
+ export const mailboxFromStream: {
3013
+ (options?: {
3014
+ readonly capacity?: number | undefined
3015
+ readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
3016
+ }): <A, E, R>(self: Stream.Stream<A, E, R>) => Effect.Effect<Mailbox.ReadonlyMailbox<A, E>, never, R | Scope.Scope>
3017
+ <A, E, R>(
3018
+ self: Stream.Stream<A, E, R>,
3019
+ options?: {
3020
+ readonly capacity?: number | undefined
3021
+ readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
3022
+ }
3023
+ ): Effect.Effect<Mailbox.ReadonlyMailbox<A, E>, never, R | Scope.Scope>
3024
+ } = dual((args) => isStream(args[0]), <A, E, R>(
3025
+ self: Stream.Stream<A, E, R>,
3026
+ options?: {
3027
+ readonly capacity?: number | undefined
3028
+ readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
3029
+ }
3030
+ ): Effect.Effect<Mailbox.ReadonlyMailbox<A, E>, never, R | Scope.Scope> =>
3031
+ effectCore.tap(
3032
+ fiberRuntime.acquireRelease(
3033
+ mailbox.make<A, E>(options),
3034
+ (mailbox) => mailbox.shutdown
3035
+ ),
3036
+ (mailbox) => {
3037
+ const writer: Channel.Channel<never, Chunk.Chunk<A>, never, E> = core.readWithCause({
3038
+ onInput: (input: Chunk.Chunk<A>) => core.flatMap(mailbox.offerAll(input), () => writer),
3039
+ onFailure: (cause: Cause.Cause<E>) => mailbox.failCause(cause),
3040
+ onDone: () => mailbox.end
3041
+ })
3042
+ return fiberRuntime.scopeWith((scope) =>
3043
+ toChannel(self).pipe(
3044
+ core.pipeTo(writer),
3045
+ channelExecutor.runIn(scope),
3046
+ circular.forkIn(scope)
3047
+ )
3048
+ )
3049
+ }
3050
+ ))
3051
+
3014
3052
  /** @internal */
3015
3053
  export const fromChunk = <A>(chunk: Chunk.Chunk<A>): Stream.Stream<A> =>
3016
3054
  new StreamImpl(Chunk.isEmpty(chunk) ? core.void : core.write(chunk))
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.21.5"
1
+ let moduleVersion = "3.22.1"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4