Durable Objects and modules
robertcepa opened this issue · 5 comments
Just wanted to give a heads up that Durable Objects and standard Workers written as modules is on my radar, but there are still many moving pieces in BETA and so I don't want to rush this. I'm expecting breaking changes in how toucan-js
is going to consume event properties like waitUntil
or request
in mjs world.
As a workaround, I believe that you might still be able to get toucan-js
working in Durable Objects BETA, but you'll need to build event
object manually and also override the event
type if you use TypeScript.
export class MyDurableObject {
constructor(state, env) {
this.state = state;
}
async fetch(request) {
const sentry = new Toucan({
event: {
waitUntil: this.state.waitUntil.bind(this.state),
request
} as any,
// ... other opts
});
...
}
}
https://community.cloudflare.com/t/2021-4-15-workers-runtime-release-notes/261917
waitUntil is now supported for module workers. An additional argument called ‘ctx’ is passed after ‘env’, and waitUntil is a method on ‘ctx’.
Should be able to get this fully working natively now!
Note that durable objects themselves have had waitUntil
for awhile now, it's the es modules that haven't until a couple days ago.
https://developers.cloudflare.com/workers/runtime-apis/durable-objects
Just implemented. Looks like it's working great! Will keep an eye on it and report anything I see. Thanks for the update!