Skip to content

Commit

Permalink
[queues] correct DurableObject to DurableObjectNamespace & remove…
Browse files Browse the repository at this point in the history
… constructor block (#14529)

* correct `DurableObject` to `DurableObjectNamespace`

* remove constructor block and made `env` public

* add failure response

* Update content/queues/examples/use-queues-with-durable-objects.md

Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com>

---------

Co-authored-by: Maddy <130055405+Maddy-Cloudflare@users.noreply.github.com>
  • Loading branch information
helloimalastair and Maddy-Cloudflare committed May 14, 2024
1 parent 81b7ab2 commit d65e82f
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions content/queues/examples/use-queues-with-durable-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ filename: src/index.ts
---
interface Env {
YOUR_QUEUE: Queue;
YOUR_DO_CLASS: DurableObject;
YOUR_DO_CLASS: DurableObjectNamespace;
}

export default {
Expand All @@ -74,17 +74,12 @@ export default {
// This would return "wrote to queue", but you could return any response.
return response;
}
return new Response("userId must be provided", { status: 400 });
}
}

export class YourDurableObject implements DurableObject {
constructor(public state: DurableObjectState, env: Env) {
this.state = state;
// Ensure you pass your bindings and environment variables into
// each Durable Object when it is initialized
this.env = env;
}
}
constructor(private state: DurableObjectState, private env: Env) {}

async fetch(request: Request) {
// Error handling elided for brevity.
Expand Down

0 comments on commit d65e82f

Please sign in to comment.