Skip to content

port library to effect v4#19

Draft
fiws wants to merge 1 commit into
mainfrom
effect-v4
Draft

port library to effect v4#19
fiws wants to merge 1 commit into
mainfrom
effect-v4

Conversation

@fiws
Copy link
Copy Markdown
Collaborator

@fiws fiws commented May 23, 2026

No description provided.

@fiws fiws self-assigned this May 23, 2026
Comment thread src/keyboard.ts
text: Parameters<Keyboard["type"]>[0],
options?: Parameters<Keyboard["type"]>[1],
) => use((k) => k.type(text, options)),
up: (key: Parameters<Keyboard["up"]>[0]) => use((k) => k.up(key)),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless change i think.

Comment thread src/page.ts
Stream.callback<PageEvents[K]>((queue) => {
const handler = (value: PageEvents[K]) =>
Queue.offerUnsafe(queue, value);
const closeHandler = () => Queue.endUnsafe(queue);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duno..

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ai says:

Yes, we absolutely need the queue because of a core architectural change in how Effect v4 handles asynchronous callbacks.

1. The v3 vs v4 API change

In Effect v3, eventStream used Stream.asyncPush, which provided an emit object. You had to call emit.single(value) to push a
value and emit.end() to close the stream:

  // v3 (asyncPush)
  Stream.asyncPush((emit) => {
    context.on(event, emit.single);
    context.once("close", emit.end);
  })

In Effect v4, Stream.asyncPush was deprecated and unified into Stream.callback. Its callback f no longer receives a custom
emit object; instead, it receives a standard Effect Queue (Queue.Queue<A, E | Cause.Done>):

  // v4 (callback)
  Stream.callback((queue) => { ... })

2. Why did Effect make this change?

In v3, emit was an ad-hoc, proprietary object interface created specifically for async streams.

By changing this to a standard Queue in v4, Effect:

  1. Consolidated APIs: Unified the stream-callback protocol with the standard Queue primitive.
  2. Improved Customizability: Allows you to leverage standard Queue operations (such as capacity bounds, backpressure, custom
    drop/slide strategies, and safety utilities) directly inside callbacks.
  3. Optimized Performance: The underlying fiber runtime can pipe the Queue directly into channels under-the-hood without
    wrapping it in an extra intermediate adapter.

3. How we interact with the Queue

To push event values onto the queue safely from the Playwright event-emitter context (which is synchronous/non-effectful), we
use Effect's fast, synchronous push APIs:

  • Queue.offerUnsafe(queue, value): Instantly pushes an event down the stream without requiring an Effect context.
  • Queue.endUnsafe(queue): Signals that the event stream is finished (e.g. when a page or browser context closes).

Comment thread src/common.test.ts Outdated
Effect.flatten,
);
const fileChooserOpt = yield* Fiber.join(fileChooserFiber);
const fileChooser = Option.getOrThrow(fileChooserOpt);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOrThrow is not effecty

Comment thread src/browser.ts
browser.newContext(options).then(PlaywrightBrowserContext.make),
),
(context) => context.close.pipe(Effect.ignoreLogged),
(context) => context.close.pipe(Effect.ignore),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoreLogged no longer a thing? investigate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant