Skip to content

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

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

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

Conversation

@cowboyd

Copy link
Copy Markdown
Member

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
Copy Markdown

Open in StackBlitz

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

commit: 066bbba

@tarastaras left a comment

Copy link
Copy Markdown
Member

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 v4Jan 26, 2026
15 checks passed
@cowboyd
cowboyd deleted the simplify-scope-run branch January 26, 2026 17:12
@cowboyd

Copy link
Copy Markdown
MemberAuthor

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

letscope=yield*useScope();returnscope.run(op);

@taras

Copy link
Copy Markdown
Member

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

@cowboyd

Copy link
Copy Markdown
MemberAuthor

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

@cowboydcowboyd mentioned this pull request Jul 8, 2026
Sign up for freeto 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

@cowboyd@taras@jbolda