effect 3.22.0 → 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 (56) hide show
  1. package/dist/cjs/Context.js +1 -1
  2. package/dist/cjs/Mailbox.js +3 -2
  3. package/dist/cjs/Mailbox.js.map +1 -1
  4. package/dist/cjs/ParseResult.js +18 -0
  5. package/dist/cjs/ParseResult.js.map +1 -1
  6. package/dist/cjs/internal/config.js +5 -1
  7. package/dist/cjs/internal/config.js.map +1 -1
  8. package/dist/cjs/internal/configProvider.js +14 -1
  9. package/dist/cjs/internal/configProvider.js.map +1 -1
  10. package/dist/cjs/internal/effect/circular.js +5 -4
  11. package/dist/cjs/internal/effect/circular.js.map +1 -1
  12. package/dist/cjs/internal/mailbox.js +11 -19
  13. package/dist/cjs/internal/mailbox.js.map +1 -1
  14. package/dist/cjs/internal/opCodes/config.js +3 -1
  15. package/dist/cjs/internal/opCodes/config.js.map +1 -1
  16. package/dist/cjs/internal/stream/emit.js +6 -34
  17. package/dist/cjs/internal/stream/emit.js.map +1 -1
  18. package/dist/cjs/internal/stream.js +26 -16
  19. package/dist/cjs/internal/stream.js.map +1 -1
  20. package/dist/cjs/internal/version.js +1 -1
  21. package/dist/dts/Context.d.ts +1 -1
  22. package/dist/dts/Mailbox.d.ts.map +1 -1
  23. package/dist/dts/ParseResult.d.ts.map +1 -1
  24. package/dist/dts/internal/stream.d.ts.map +1 -1
  25. package/dist/esm/Context.js +1 -1
  26. package/dist/esm/Mailbox.js +3 -2
  27. package/dist/esm/Mailbox.js.map +1 -1
  28. package/dist/esm/ParseResult.js +18 -0
  29. package/dist/esm/ParseResult.js.map +1 -1
  30. package/dist/esm/internal/config.js +5 -1
  31. package/dist/esm/internal/config.js.map +1 -1
  32. package/dist/esm/internal/configProvider.js +14 -1
  33. package/dist/esm/internal/configProvider.js.map +1 -1
  34. package/dist/esm/internal/effect/circular.js +5 -4
  35. package/dist/esm/internal/effect/circular.js.map +1 -1
  36. package/dist/esm/internal/mailbox.js +10 -17
  37. package/dist/esm/internal/mailbox.js.map +1 -1
  38. package/dist/esm/internal/opCodes/config.js +2 -0
  39. package/dist/esm/internal/opCodes/config.js.map +1 -1
  40. package/dist/esm/internal/stream/emit.js +6 -34
  41. package/dist/esm/internal/stream/emit.js.map +1 -1
  42. package/dist/esm/internal/stream.js +22 -13
  43. package/dist/esm/internal/stream.js.map +1 -1
  44. package/dist/esm/internal/version.js +1 -1
  45. package/package.json +1 -1
  46. package/src/Context.ts +1 -1
  47. package/src/Mailbox.ts +3 -2
  48. package/src/ParseResult.ts +18 -0
  49. package/src/internal/config.ts +14 -1
  50. package/src/internal/configProvider.ts +24 -1
  51. package/src/internal/effect/circular.ts +5 -4
  52. package/src/internal/mailbox.ts +13 -52
  53. package/src/internal/opCodes/config.ts +6 -0
  54. package/src/internal/stream/emit.ts +7 -39
  55. package/src/internal/stream.ts +62 -24
  56. package/src/internal/version.ts +1 -1
@@ -9,7 +9,6 @@ import * as Either from "../Either.js";
9
9
  import * as Equal from "../Equal.js";
10
10
  import * as Exit from "../Exit.js";
11
11
  import * as Fiber from "../Fiber.js";
12
- import * as FiberRef from "../FiberRef.js";
13
12
  import { constTrue, dual, identity, pipe } from "../Function.js";
14
13
  import * as internalExecutionPlan from "../internal/executionPlan.js";
15
14
  import * as Layer from "../Layer.js";
@@ -31,7 +30,11 @@ import * as channel from "./channel.js";
31
30
  import * as channelExecutor from "./channel/channelExecutor.js";
32
31
  import * as MergeStrategy from "./channel/mergeStrategy.js";
33
32
  import * as core from "./core-stream.js";
33
+ import * as effectCore from "./core.js";
34
34
  import * as doNotation from "./doNotation.js";
35
+ import * as circular from "./effect/circular.js";
36
+ import * as fiberRuntime from "./fiberRuntime.js";
37
+ import * as mailbox from "./mailbox.js";
35
38
  import { RingBuffer } from "./ringBuffer.js";
36
39
  import * as InternalSchedule from "./schedule.js";
37
40
  import * as sink_ from "./sink.js";
@@ -220,22 +223,17 @@ export const asyncEffect = (register, bufferSize) => pipe(Effect.acquireRelease(
220
223
  }), channel.unwrap);
221
224
  return loop;
222
225
  }))))), channel.unwrapScoped, fromChannel);
223
- const queueFromBufferOptionsPush = options => {
226
+ const mailboxFromBufferOptionsPush = options => {
224
227
  if (options?.bufferSize === "unbounded" || options?.bufferSize === undefined && options?.strategy === undefined) {
225
- return Queue.unbounded();
226
- }
227
- switch (options?.strategy) {
228
- case "sliding":
229
- return Queue.sliding(options.bufferSize ?? 16);
230
- default:
231
- return Queue.dropping(options?.bufferSize ?? 16);
228
+ return mailbox.make();
232
229
  }
230
+ return mailbox.make({
231
+ capacity: options?.bufferSize ?? 16,
232
+ strategy: options?.strategy ?? "dropping"
233
+ });
233
234
  };
234
235
  /** @internal */
235
- export const asyncPush = (register, options) => Effect.acquireRelease(queueFromBufferOptionsPush(options), Queue.shutdown).pipe(Effect.tap(queue => FiberRef.getWith(FiberRef.currentScheduler, scheduler => register(emit.makePush(queue, scheduler)))), Effect.map(queue => {
236
- const loop = core.flatMap(Queue.take(queue), item => Exit.isExit(item) ? Exit.isSuccess(item) ? core.void : core.failCause(item.cause) : channel.zipRight(core.write(Chunk.unsafeFromArray(item)), loop));
237
- return loop;
238
- }), channel.unwrapScoped, fromChannel);
236
+ export const asyncPush = (register, options) => Effect.acquireRelease(mailboxFromBufferOptionsPush(options), mailbox => mailbox.shutdown).pipe(Effect.tap(mailbox => register(emit.makePush(mailbox))), Effect.map(mailboxToStream), unwrapScoped);
239
237
  /** @internal */
240
238
  export const asyncScoped = (register, bufferSize) => pipe(Effect.acquireRelease(queueFromBufferOptions(bufferSize), queue => Queue.shutdown(queue)), Effect.flatMap(output => pipe(Effect.runtime(), Effect.flatMap(runtime => pipe(register(emit.make(k => pipe(InternalTake.fromPull(k), Effect.flatMap(take => Queue.offer(output, take)), Effect.asVoid, Runtime.runPromiseExit(runtime)).then(exit => {
241
239
  if (Exit.isFailure(exit)) {
@@ -923,6 +921,17 @@ export const toChannel = stream => {
923
921
  }
924
922
  };
925
923
  /** @internal */
924
+ export const mailboxToStream = self => fromChannel(mailbox.toChannel(self));
925
+ /** @internal */
926
+ export const mailboxFromStream = /*#__PURE__*/dual(args => isStream(args[0]), (self, options) => effectCore.tap(fiberRuntime.acquireRelease(mailbox.make(options), mailbox => mailbox.shutdown), mailbox => {
927
+ const writer = core.readWithCause({
928
+ onInput: input => core.flatMap(mailbox.offerAll(input), () => writer),
929
+ onFailure: cause => mailbox.failCause(cause),
930
+ onDone: () => mailbox.end
931
+ });
932
+ return fiberRuntime.scopeWith(scope => toChannel(self).pipe(core.pipeTo(writer), channelExecutor.runIn(scope), circular.forkIn(scope)));
933
+ }));
934
+ /** @internal */
926
935
  export const fromChunk = chunk => new StreamImpl(Chunk.isEmpty(chunk) ? core.void : core.write(chunk));
927
936
  /** @internal */
928
937
  export const fromChunkPubSub = (pubsub, options) => {