Skip to content

Commit a6ecc64

Browse files
Oxyjunsdnts
authored andcommitted
[Durable Objects] Adding warning for calling setAlarm from inside the constructor (cloudflare#22746)
* Adding warning for calling setAlarm from inside the DO constructor. * Clarification of wording
1 parent d520aa4 commit a6ecc64

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Alarms can be used to build distributed primitives, like queues or batching of w
4545
- Set the time for the alarm to run. Specify the time as the number of milliseconds elapsed since the UNIX epoch.
4646
- If you call `setAlarm` when there is already one scheduled, it will override the existing alarm.
4747

48+
:::caution[Calling `setAlarm` inside the constructor]
49+
If you wish to call `setAlarm` inside the constructor of a Durable Object, ensure that you are first checking whether an alarm has already been set.
50+
51+
This is due to the fact that, if the Durable Object wakes up after being inactive, the constructor is invoked before the [`alarm` handler](/durable-objects/api/alarms/#alarm). Therefore, if the constructor calls `setAlarm`, it could interfere with the next alarm which has already been set.
52+
:::
53+
4854
### `deleteAlarm`
4955

5056
- `deleteAlarm()`: <Type text='void' />

0 commit comments

Comments
 (0)