Skip to content

Commit 7ab17b2

Browse files
committed
Address remaining comments
1 parent c3ee93b commit 7ab17b2

File tree

4 files changed

+41
-52
lines changed

4 files changed

+41
-52
lines changed

src/content/docs/durable-objects/api/alarms.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ Alarms can be used to build distributed primitives, like queues or batching of w
3737

3838
### getAlarm
3939

40-
- <code>getAlarm()</code>: <Type text ='number | null' />
40+
- <code>getAlarm()</code>: <Type text="number | null" />
4141

4242
- 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`.
4343

4444
### setAlarm
4545

46-
- <code> setAlarm(scheduledTimeMs <Type text="number" />)</code>: <Type text="void" />
46+
- <code>
47+
{" "}
48+
setAlarm(scheduledTimeMs <Type text="number" />)
49+
</code>
50+
: <Type text="void" />
4751

48-
- 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.
4953

5054
### deleteAlarm
5155

@@ -72,7 +76,7 @@ Alarms can be used to build distributed primitives, like queues or batching of w
7276
This example shows how to both set alarms with the `setAlarm(timestamp)` method and handle alarms with the `alarm()` handler within your Durable Object.
7377

7478
- 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.
7680
- Following a short delay, the `alarm()` handler will run from the beginning on the other machine.
7781

7882
```js

src/content/docs/durable-objects/api/id.mdx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,29 @@ If you are experiencing an issue with a particular Durable Object instance, you
2323

2424
### `toString`
2525

26-
#### Description
27-
2826
`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`.
2927

3028
```js
3129
// Create a new unique ID
3230
const id = 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
32+
const session_id = id.toString();
33+
3434
...
3535
// Recreate the ID from the string
3636
const id = env.MY_DURABLE_OBJECT.idFromString(session_id);
3737
```
3838

3939
#### Parameters
4040

41-
None.
41+
- None.
4242

43-
#### Return value
43+
#### Return values
4444

45-
A 64 digit hex string.
45+
- A 64 digit hex string.
4646

4747
### `equals`
4848

49-
#### Description
50-
5149
`equals` is used to compare equality between two instances of `DurableObjectId`.
5250

5351
```js
@@ -58,25 +56,26 @@ console.assert(!id1.equals(id2), "Different unique ids should never be equal.");
5856

5957
#### Parameters
6058

61-
A required `DurableObjectId` to compare against.
59+
- A required `DurableObjectId` to compare against.
6260

63-
#### Return value
61+
#### Return values
6462

65-
A boolean. True if equal and false otherwise.
63+
- A boolean. True if equal and false otherwise.
6664

6765
## Properties
6866

6967
### `name`
7068

71-
#### Description
72-
7369
`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).
7470

7571
```js
7672
const uniqueId = env.MY_DURABLE_OBJECT.newUniqueId();
7773
const fromNameId = env.MY_DURABLE_OBJECT.idFromName("foo");
7874
console.assert(uniqueId.name === undefined, "unique ids have no name");
79-
console.assert(fromNameId.name === "foo", "name matches parameter to idFromName");
75+
console.assert(
76+
fromNameId.name === "foo",
77+
"name matches parameter to idFromName",
78+
);
8079
```
8180

8281
## Related resources

src/content/docs/durable-objects/api/namespace.mdx

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
// Every unique ID refers to an individual instance of the Durable Object class
3030
const id = env.MY_DURABLE_OBJECT.idFromName("foo");
3131

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
3333
const stub = env.MY_DURABLE_OBJECT.get(id);
3434
...
3535
}
@@ -56,7 +56,7 @@ export default {
5656
// Every unique ID refers to an individual instance of the Durable Object class
5757
const id = env.MY_DURABLE_OBJECT.idFromName("foo");
5858

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
6060
const stub = env.MY_DURABLE_OBJECT.get(id);
6161
...
6262
}
@@ -69,8 +69,6 @@ export default {
6969

7070
### `idFromName`
7171

72-
#### Description
73-
7472
`idFromName` creates a [`DurableObjectId`](/durable-objects/api/id) which refers to an individual instance of the Durable Object class from a particular name.
7573

7674
```js
@@ -80,16 +78,14 @@ const barId = env.MY_DURABLE_OBJECT.idFromName("bar");
8078

8179
#### Parameters
8280

83-
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.
8482

85-
#### Return value
83+
#### Return values
8684

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.
8886

8987
### `newUniqueId`
9088

91-
#### Description
92-
9389
`newUniqueId` creates a `DurableObjectId` which refers to an individual instance of the Durable Object class.
9490

9591
```js
@@ -105,16 +101,14 @@ IDs created by `newUniqueId` will result in lower latencies when getting a [`Dur
105101

106102
#### Parameters
107103

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.
109105

110-
#### Return value
106+
#### Return values
111107

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.
113109

114110
### `idFromString`
115111

116-
#### Description
117-
118112
`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.
119113

120114
```js
@@ -128,16 +122,14 @@ const id = env.MY_DURABLE_OBJECT.idFromString(session_id);
128122

129123
#### Parameters
130124

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`.
132126

133-
#### Return value
127+
#### Return values
134128

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.
136130

137131
### `get`
138132

139-
#### Description
140-
141133
`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.
142134

143135
```js
@@ -147,16 +139,14 @@ const stub = env.MY_DURABLE_OBJECT.get(id);
147139

148140
#### Parameters
149141

150-
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.
151143

152-
#### Return value
144+
#### Return values
153145

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.
155147

156148
### `jurisdiction`
157149

158-
#### Description
159-
160150
`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).
161151

162152
```js
@@ -166,13 +156,13 @@ const euId = subnamespace.idFromName("foo");
166156

167157
#### Parameters
168158

169-
A required [jurisdiction](/durable-objects/reference/data-location/#restrict-durable-objects-to-a-jurisdiction) string.
159+
- A required [jurisdiction](/durable-objects/reference/data-location/#restrict-durable-objects-to-a-jurisdiction) string.
170160

171-
#### Return value
161+
#### Return values
172162

173-
A `DurableObjectNamespace` scoped to a particular geographic jurisdiction.
163+
- A `DurableObjectNamespace` scoped to a particular geographic jurisdiction.
174164

175165
## Related resources
176166

177167
- [Durable Objects: Easy, Fast, Correct – Choose Three](https://blog.cloudflare.com/durable-objects-easy-fast-correct-choose-three/).
178-
- [Durable Objects best practices](/durable-objects/best-practices/access-durable-objects-from-a-worker/).
168+
- [Durable Objects best practices](/durable-objects/best-practices/access-durable-objects-from-a-worker/).

src/content/docs/durable-objects/api/stub.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class MyDurableObject extends DurableObject {
5959
super(ctx, env);
6060
}
6161

62-
sayHello(): String {
62+
async sayHello(): String {
6363
return "Hello, World!";
6464
}
6565
}
@@ -74,7 +74,7 @@ export default {
7474
const stub = env.MY_DURABLE_OBJECT.get(id);
7575

7676
// Methods on the Durable Object are invoked via the stub
77-
const rpcResponse = stub.sayHello();
77+
const rpcResponse = await stub.sayHello();
7878

7979
return new Response(rpcResponse);
8080
},
@@ -87,8 +87,6 @@ export default {
8787

8888
### `id`
8989

90-
#### Description
91-
9290
`id` is a property of the `DurableObjectStub` corresponding to the [`DurableObjectId`](/durable-objects/api/id) used to create the stub.
9391

9492
```js
@@ -99,8 +97,6 @@ console.assert(id.equals(stub.id), "This should always be true");
9997

10098
### `name`
10199

102-
#### Description
103-
104100
`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).
105101

106102
```js

0 commit comments

Comments
 (0)