You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Address confusing comment around input and output gates (cloudflare#19058)
* Address confusing comment around input and output gates
* Update src/content/docs/durable-objects/api/storage-api.mdx
Co-authored-by: Jun Lee <[email protected]>
---------
Co-authored-by: Jun Lee <[email protected]>
The Durable Object Storage API allows <GlossaryTooltipterm="Durable Object">Durable Objects</GlossaryTooltip> to access transactional and strongly consistent storage. A Durable Object's attached storage is private to its unique instance and cannot be accessed by other objects.
11
17
@@ -18,9 +24,9 @@ Note that Durable Object storage is scoped by individual <GlossaryTooltip term="
18
24
However, storage is scoped per individual Durable Object.
19
25
:::
20
26
21
-
Durable Objects gain access to a persistent Durable Object Storage API via `ctx.storage`, on the `ctx` parameter passed to the Durable Object constructor.
27
+
Durable Objects gain access to a persistent Durable Object Storage API via the `DurableObjectStorage` interface and accessed by the `DurableObjectState::storage` property. This is frequently accessed via `this.ctx.storage` when the `ctx` parameter passed to the Durable Object constructor.
22
28
23
-
While access to a Durable Object is single-threaded, request executions can still interleave with each other when they wait on I/O, such as when waiting on the promises returned by persistent storage methods or `fetch()` requests.
29
+
JavaScript is a single-threaded and event-driven programming language. This means that JavaScript runtimes, by default, allow requests to interleave with each other which can lead to concurrency bugs. The Durable Objects runtime uses a combination of <GlossaryTooltipterm="input gate">input gates</GlossaryTooltip> and <GlossaryTooltipterm="output gate">output gates</GlossaryTooltip> to avoid this type of concurrency bug when performing storage operations.
24
30
25
31
The following code snippet shows you how to store and retrieve data using the Durable Object Storage API.
26
32
@@ -31,13 +37,15 @@ export class Counter extends DurableObject {
31
37
super(ctx, env);
32
38
}
33
39
34
-
async increment():Promise<number> {
35
-
let value:number= (awaitthis.ctx.storage.get('value')) ||0;
36
-
value+=1;
37
-
awaitthis.ctx.storage.put('value', value);
38
-
returnvalue;
39
-
}
40
+
async increment():Promise<number> {
41
+
let value:number= (awaitthis.ctx.storage.get('value')) ||0;
42
+
value+=1;
43
+
awaitthis.ctx.storage.put('value', value);
44
+
returnvalue;
45
+
}
46
+
40
47
}
48
+
41
49
```
42
50
</TypeScriptExample>
43
51
@@ -255,3 +263,4 @@ The `put()` method returns a `Promise`, but most applications can discard this p
Copy file name to clipboardExpand all lines: src/content/glossary/durable-objects.yaml
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -63,3 +63,11 @@ entries:
63
63
- term: "event context"
64
64
general_definition: |-
65
65
The duration of time that a Durable Object is processing an event, such as a remote procedure call. [Compute duration charges](/durable-objects/platform/pricing) are incurred for the duration of the event context.
66
+
67
+
- term: "input gate"
68
+
general_definition: |-
69
+
While a storage operation is executing, no events shall be delivered to a Durable Object except for storage completion events. Any other events will be deferred until such a time as the object is no longer executing JavaScript code and is no longer waiting for any storage operations. We say that these events are waiting for the "input gate" to open.
70
+
71
+
- term: "output gate"
72
+
general_definition: |-
73
+
When a storage write operation is in progress, any new outgoing network messages will be held back until the write has completed. We say that these messages are waiting for the "output gate" to open. If the write ultimately fails, the outgoing network messages will be discarded and replaced with errors, while the Durable Object will be shut down and restarted from scratch.
0 commit comments