Skip to content

Add WORKER_LOADER.load() for one-off workers. #6316

Merged
kentonv merged 2 commits intomainfrom
kenton/worker-loader-load
Mar 14, 2026
Merged

Add WORKER_LOADER.load() for one-off workers. #6316
kentonv merged 2 commits intomainfrom
kenton/worker-loader-load

Conversation

@kentonv
Copy link
Member

@kentonv kentonv commented Mar 12, 2026

LOADER.load(code) is equivalent to LOADER.get(null, () => code). This is nice for the common use case of e.g. agent-generated one-off code.

This change got annoying to the pesky detail that the system might call the callback multiple times, forcing me to create clone() methods for a bunch of structures so that I could build the structure ones and return a clone on every call. The source code itself is refcounted between these clones, at least.

Note: Eventually we might support plain RPC stubs in env in this case, but that's a deep change which I'm not going to attempt right now.

This is a pure code move into a helper function.
@kentonv kentonv requested a review from danlapid March 12, 2026 23:48
@kentonv kentonv requested review from a team as code owners March 12, 2026 23:48
@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 12, 2026

LGTM

github run

@ask-bonk ask-bonk bot requested a review from a team as a code owner March 12, 2026 23:53
@kentonv kentonv force-pushed the kenton/worker-loader-load branch from 37019c4 to 8969e17 Compare March 12, 2026 23:56
@github-actions
Copy link

github-actions bot commented Mar 13, 2026

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@kentonv kentonv force-pushed the kenton/worker-loader-load branch from 8969e17 to 79d7d94 Compare March 13, 2026 13:03
`LOADER.load(code)` is equivalent to `LOADER.get(null, () => code)`.

This change got annoying to the pesky detail that the system might call the callback multiple times, forcing me to create clone() methods for a bunch of structures so that I could build the structure ones and return a clone on every call. The source code itself is refcounted between these clones, at least.
@kentonv kentonv force-pushed the kenton/worker-loader-load branch from 79d7d94 to e945af7 Compare March 13, 2026 14:38
@kentonv kentonv merged commit 87395c3 into main Mar 14, 2026
24 checks passed
@kentonv kentonv deleted the kenton/worker-loader-load branch March 14, 2026 23:39
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.

2 participants