Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a Durable Object to create new unique ids and get ids from a string #24

Merged
merged 1 commit into from Aug 25, 2022

Conversation

jacwright
Copy link
Contributor

@jacwright jacwright commented Aug 25, 2022

In a durable object, the proxies overwrite the stubs on state. This will allow a durable object to still be able to create new ids and convert id strings to id objects for use in Proxy.get(id).

const stub = this.state.env.Counter;
const newId = stub.newUniqueId();
const idObj = stub.idFromString(storedObjectId);
this.state.Counter.get(newId).increment();
this.state.Counter.get(idObj).increment();

This is needed for creating fan-out systems or connection pooling like https://github.com/cloudflare/dog/.

…ring

In a durable object, the proxies overwrite the stubs on state. This will allow a durable object to still be able to create new ids and convert is strings to id objects for use in DOProxy.get(id).

```js
const stub = this.env.Counter;
const newId = stub.newUniqueId();
const idObj = stub.idFromString(storedObjectId);
```

This is needed for creating fan-out systems or connection pooling like https://github.com/cloudflare/dog/.
@kwhitley
Copy link
Owner

No objections here!

@kwhitley kwhitley merged commit 96b148a into kwhitley:v1.x Aug 25, 2022
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.

None yet

2 participants