Durable_objects access from different workers

Can a durable_object be accessed from different workers?

From the way they are defined in wrangler, one has to bind the object’s class in the wranlger.toml definition.

So if I have a class called Counter that I define as a durable object in worker A, and I have a completely different worker, let’s say worker B, how could I access Counter from worker B?

Maybe one way would be to define the same class in both workers adn bind it under the same name?

The Durable Objects docs mention using script_name (the name of the script where the Durable Object class was defined, exported and published) to access a Durable Object class from another script.

[durable_objects]
bindings = [{name = "EXAMPLE_CLASS", class_name = "DurableObjectExample", script_name = "example-name"}]

Thanks @albert!
Yeah I saw that in the doc except I’m not sure how that helps with the two workers issue. Would you define a worker that would be shared between the 2 code bases? And more importantly would you be able to increment a counter form one worker for instance and retrieve its value form another worker?

Yes. Durable Objects are separate from the Worker calling them. You can bind the same class in multiple scripts no problem :slightly_smiling_face:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.