Skip to content

♻️ simplify spawn() by delegating to scope.run#1078

Merged
cowboyd merged 1 commit intov4from
simplify-scope-run
Jan 26, 2026
Merged

♻️ simplify spawn() by delegating to scope.run#1078
cowboyd merged 1 commit intov4from
simplify-scope-run

Conversation

@cowboyd
Copy link
Member

@cowboyd cowboyd commented Jan 17, 2026

Motivation

We're going to end up wrapping unified APIs around most Effection functions so that they can be decorated with middleware. As such, there is no need to have separate code paths for Scope.run() and Scope.spawn() since they end up calling the same thing under the hood.

Approach

This has spawn() delegate to Scope.run() so that the apis can be unified and wrapped as one. In other words, wraping Scope.run() is the same as wrapping spawn().

We're going to end up wrapping unified APIs around most Effection
functions so that they can be decorated with middleware. As such, there
is no need to have separate code paths for Scope.run() and
Scope.spawn() since they end up calling the same thing under the hood.

This has `spawn()`` delegate to `Scope.run()` so that the apis can be
unified and wrapped as one. In other words, wraping `Scope.run()` is
the same as wrapping `spawn()`.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/thefrontside/effection@1078

commit: 066bbba

Copy link
Member

@taras taras left a comment

Choose a reason for hiding this comment

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

🤯 how is this is even possible?

@cowboyd cowboyd merged commit 253ce61 into v4 Jan 26, 2026
15 checks passed
@cowboyd cowboyd deleted the simplify-scope-run branch January 26, 2026 17:12
@cowboyd
Copy link
Member Author

cowboyd commented Jan 26, 2026

@taras I was actually surprised at how simple the change was. Turns out, the spawn operation is just this:

  let scope = yield* useScope();
  return scope.run(op);

@taras
Copy link
Member

taras commented Jan 26, 2026

Isn't run also that? How are they not same?

@cowboyd
Copy link
Member Author

cowboyd commented Jan 26, 2026

They both resolve to createTask() This makes sure that we take the exact same codepath to get there.

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.

3 participants