feat(cloudflare): bind Workflows to async Workers - #707
Merged
Conversation
Add a props-only reference form `Workflow(name, { className, scriptName })`
that returns a plain `WorkflowLike`, parallel to async Durable Objects, so a
class-based `WorkflowEntrypoint` can be bound to a non-Effect Worker via `env`:
```ts
export const AsyncWorker = Cloudflare.Worker("Async", {
main: "./src/worker.ts",
env: {
MY_WORKFLOW: Cloudflare.Workflow<{ value: string }>("MyWorkflow", {
className: "MyWorkflow",
}),
},
});
export type AsyncWorkerEnv = Cloudflare.InferEnv<typeof AsyncWorker>;
```
- WorkerAsyncBindings emits the `workflow` binding and creates a
WorkflowResource (putWorkflow) for locally-hosted workflows; cross-script
`scriptName` refs are binding-only.
- InferEnv maps `WorkflowLike<Params>` to the native `Workflow<Params>`.
- Platform.onCreate may now yield child resources (requirement discharged by
the surrounding stack provider context).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
Install the packages built from this commit: alchemy bun add alchemy@https://pkg.ing/alchemy/67e1060@alchemy.run/better-auth bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/67e1060@alchemy.run/pr-package bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/67e1060 |
Add a `test.provider` case where a consumer Worker binds a Workflow hosted by another Worker script via `scriptName` (reference-only) and drives create+get across the cross-script reference. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
DavidJFelix
pushed a commit
to DavidJFelix/alchemy-effect
that referenced
this pull request
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bind class-based Cloudflare Workflows to async (non-Effect) Workers via
env, mirroring how class-based Durable Objects already work.What changed
Added a props-only reference form
Workflow(name, { className, scriptName })that returns a plainWorkflowLike(parallel toDurableObjectLike), then wired it through every binding layer:Workflow.ts—WorkflowRefProps,WorkflowLike<Params>,isWorkflowLikeguard, and the props-only runtime branch (Effect.isEffectdisambiguates from the existing Effect-native form, which is unchanged).WorkerBinding.ts—WorkflowLikeadded to theWorkerBindingResourceunion soenvaccepts it.WorkerAsyncBindings.ts— emits theworkflowbinding and creates aWorkflowResource(putWorkflow) for locally-hosted workflows. Cross-scriptscriptNamerefs are binding-only (host owns the resource), same as async DOs.InferEnv.ts— mapsWorkflowLike<Params>to the nativeWorkflow<Params>.Platform.ts— theonCreatehook's requirement channel is widened fromnevertoanyso it may yield child resources. The requirement is always discharged by the surrounding stack provider context.Tests
New fixture + live test: a plain async Worker hosting a
WorkflowEntrypointclass, bound viaenv, starts an instance and polls tocomplete. Passes against real Cloudflare (ALCHEMY_PROFILE=testing).