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
- If there is an alarm set, then return the currently set alarm time as the number of milliseconds elapsed since the UNIX epoch. Otherwise, return `null`.
- Set the time for the alarm to run. Specify the time as the number of milliseconds elapsed since the UNIX epoch.
52
+
- Set the time for the alarm to run. Specify the time as the number of milliseconds elapsed since the UNIX epoch.
49
53
50
54
### deleteAlarm
51
55
@@ -72,7 +76,7 @@ Alarms can be used to build distributed primitives, like queues or batching of w
72
76
This example shows how to both set alarms with the `setAlarm(timestamp)` method and handle alarms with the `alarm()` handler within your Durable Object.
73
77
74
78
- The `alarm()` handler will be called once every time an alarm fires.
75
-
- If an unexpected error terminates the Durable Object, the `alarm()` handler will be re-instantiated on another machine.
79
+
- If an unexpected error terminates the Durable Object, the `alarm()` handler may be re-instantiated on another machine.
76
80
- Following a short delay, the `alarm()` handler will run from the beginning on the other machine.
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/api/id.mdx
+13-14Lines changed: 13 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,31 +23,29 @@ If you are experiencing an issue with a particular Durable Object instance, you
23
23
24
24
### `toString`
25
25
26
-
#### Description
27
-
28
26
`toString` converts a `DurableObjectId` to a 64 digit hex string. This string is useful for logging purposes or storing the `DurableObjectId` elsewhere, for example, in a session cookie. This string can be used to reconstruct a `DurableObjectId` via `DurableObjectNamespace::idFromString`.
29
27
30
28
```js
31
29
// Create a new unique ID
32
30
constid=env.MY_DURABLE_OBJECT.newUniqueId();
33
-
// Save the unique ID elsewhere, e.g. a session cookie via id.toString()
31
+
// Convert the ID to a string to be saved elsewhere, e.g. a session cookie
`equals` is used to compare equality between two instances of `DurableObjectId`.
52
50
53
51
```js
@@ -58,25 +56,26 @@ console.assert(!id1.equals(id2), "Different unique ids should never be equal.");
58
56
59
57
#### Parameters
60
58
61
-
A required `DurableObjectId` to compare against.
59
+
-A required `DurableObjectId` to compare against.
62
60
63
-
#### Return value
61
+
#### Return values
64
62
65
-
A boolean. True if equal and false otherwise.
63
+
-A boolean. True if equal and false otherwise.
66
64
67
65
## Properties
68
66
69
67
### `name`
70
68
71
-
#### Description
72
-
73
69
`name` is an optional property of a `DurableObjectId`, which returns the name that was used to create the `DurableObjectId` via [`DurableObjectNamespace::idFromName`](/durable-objects/api/namespace/#idfromname). This value is undefined if the `DurableObjectId` was constructed using [`DurableObjectNamespace::newUniqueId`](/durable-objects/api/namespace/#newuniqueid).
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/api/namespace.mdx
+18-28Lines changed: 18 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ export default {
29
29
// Every unique ID refers to an individual instance of the Durable Object class
30
30
constid=env.MY_DURABLE_OBJECT.idFromName("foo");
31
31
32
-
// A stub is a client Object used to invoke methods on the Durable Object instance.
32
+
// A stub is a client Object used to invoke methods defined by the Durable Object instance
33
33
conststub=env.MY_DURABLE_OBJECT.get(id);
34
34
...
35
35
}
@@ -56,7 +56,7 @@ export default {
56
56
// Every unique ID refers to an individual instance of the Durable Object class
57
57
const id =env.MY_DURABLE_OBJECT.idFromName("foo");
58
58
59
-
// A stub is a client used to invoke methods on the Durable Object instance.
59
+
// A stub is a client Object used to invoke methods defined by the Durable Object instance
60
60
const stub =env.MY_DURABLE_OBJECT.get(id);
61
61
...
62
62
}
@@ -69,8 +69,6 @@ export default {
69
69
70
70
### `idFromName`
71
71
72
-
#### Description
73
-
74
72
`idFromName` creates a [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class from a particular name.
The string to be used to generate a [`DurableObjectId`](/durable-objects/api/id) corresponding to the name of a Durable Object instance.
81
+
- A required string to be used to generate a [`DurableObjectId`](/durable-objects/api/id) corresponding to the name of a Durable Object instance.
84
82
85
-
#### Return value
83
+
#### Return values
86
84
87
-
A [`DurableObjectId`](/durable-objects/api/id) referring to an instance of a Durable Object class.
85
+
-A [`DurableObjectId`](/durable-objects/api/id) referring to an instance of a Durable Object class.
88
86
89
87
### `newUniqueId`
90
88
91
-
#### Description
92
-
93
89
`newUniqueId` creates a `DurableObjectId` which refers to an individual instance of the Durable Object class.
94
90
95
91
```js
@@ -105,16 +101,14 @@ IDs created by `newUniqueId` will result in lower latencies when getting a [`Dur
105
101
106
102
#### Parameters
107
103
108
-
An optional object with the key `jurisdiction` and value of a [jurisdiction](/durable-objects/reference/data-location/#restrict-durable-objects-to-a-jurisdiction) string.
104
+
-An optional object with the key `jurisdiction` and value of a [jurisdiction](/durable-objects/reference/data-location/#restrict-durable-objects-to-a-jurisdiction) string.
109
105
110
-
#### Return value
106
+
#### Return values
111
107
112
-
A [`DurableObjectId`](/durable-objects/api/id) referring to an instance of the Durable Object class.
108
+
-A [`DurableObjectId`](/durable-objects/api/id) referring to an instance of the Durable Object class.
113
109
114
110
### `idFromString`
115
111
116
-
#### Description
117
-
118
112
`idFromString` creates a [`DurableObjectId`](/durable-objects/api/id) from a previously generated ID that has been converted to a string. This method ensures the ID is valid, for example, it checks that the ID consists of 64 hex digits.
119
113
120
114
```js
@@ -128,16 +122,14 @@ const id = env.MY_DURABLE_OBJECT.idFromString(session_id);
128
122
129
123
#### Parameters
130
124
131
-
The string corresponding to a [`DurableObjectId`](/durable-objects/api/id) previously generated either by `newUniqueId` or `idFromName`.
125
+
- A required string corresponding to a [`DurableObjectId`](/durable-objects/api/id) previously generated either by `newUniqueId` or `idFromName`.
132
126
133
-
#### Return value
127
+
#### Return values
134
128
135
-
A [`DurableObjectId`](/durable-objects/api/id) referring to an instance of a Durable Object class.
129
+
-A [`DurableObjectId`](/durable-objects/api/id) referring to an instance of a Durable Object class.
136
130
137
131
### `get`
138
132
139
-
#### Description
140
-
141
133
`get` obtains a [`DurableObjectStub`](/durable-objects/api/stub) from a [`DurableObjectId`](/durable-objects/api/id) which can be used to invoke methods on a Durable Object instance.
A required [`DurableObjectId`](/durable-objects/api/id) and an optional object with the key `locationHint` and value of a [locationHint](/durable-objects/reference/data-location/#provide-a-location-hint) string.
142
+
-A required [`DurableObjectId`](/durable-objects/api/id) and an optional object with the key `locationHint` and value of a [locationHint](/durable-objects/reference/data-location/#provide-a-location-hint) string.
151
143
152
-
#### Return value
144
+
#### Return values
153
145
154
-
A [`DurableObjectStub`](/durable-objects/api/stub) referring to an instance of a Durable Object class.
146
+
-A [`DurableObjectStub`](/durable-objects/api/stub) referring to an instance of a Durable Object class.
155
147
156
148
### `jurisdiction`
157
149
158
-
#### Description
159
-
160
150
`jurisdiction` creates a subnamespace from a namespace where all Durable Object instance IDs and references created from that subnamespace will be restricted to the specified [jurisdiction](/durable-objects/reference/data-location/#restrict-durable-objects-to-a-jurisdiction).
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/api/stub.mdx
+2-6Lines changed: 2 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ export class MyDurableObject extends DurableObject {
59
59
super(ctx, env);
60
60
}
61
61
62
-
sayHello():String {
62
+
asyncsayHello():String {
63
63
return"Hello, World!";
64
64
}
65
65
}
@@ -74,7 +74,7 @@ export default {
74
74
const stub =env.MY_DURABLE_OBJECT.get(id);
75
75
76
76
// Methods on the Durable Object are invoked via the stub
77
-
const rpcResponse =stub.sayHello();
77
+
const rpcResponse =awaitstub.sayHello();
78
78
79
79
returnnewResponse(rpcResponse);
80
80
},
@@ -87,8 +87,6 @@ export default {
87
87
88
88
### `id`
89
89
90
-
#### Description
91
-
92
90
`id` is a property of the `DurableObjectStub` corresponding to the [`DurableObjectId`](/durable-objects/api/id) used to create the stub.
93
91
94
92
```js
@@ -99,8 +97,6 @@ console.assert(id.equals(stub.id), "This should always be true");
99
97
100
98
### `name`
101
99
102
-
#### Description
103
-
104
100
`name` is an optional property of a `DurableObjectStub`, which returns the name that was used to create the [`DurableObjectId`](/durable-objects/api/id) via [`DurableObjectNamespace::idFromName`](/durable-objects/api/namespace/#idfromname) which was then used to create the `DurableObjectStub`. This value is undefined if the [`DurableObjectId`](/durable-objects/api/id) used to create the `DurableObjectStub` was constructed using [`DurableObjectNamespace::newUniqueId`](/durable-objects/api/namespace/#newuniqueid).
0 commit comments