@@ -231,11 +231,8 @@ jsg::Promise<jsg::Value> DurableObjectStorageOperations::getOne(
231
231
232
232
jsg::Promise<kj::Maybe<double >> DurableObjectStorageOperations::getAlarm (
233
233
jsg::Optional<GetAlarmOptions> maybeOptions, v8::Isolate* isolate) {
234
-
235
- if (!IoContext::current ().getActorOrThrow ().hasAlarmHandler ()) {
236
- return jsg::resolvedPromise<kj::Maybe<double >>(isolate, nullptr );
237
- }
238
-
234
+ // Even if we do not have an alarm handler, we might once have had one. It's fine to return
235
+ // whatever a previous alarm setting or a falsy result.
239
236
auto options = configureOptions (maybeOptions.map ([](auto & o) {
240
237
return GetOptions {
241
238
.allowConcurrency = o.allowConcurrency ,
@@ -400,8 +397,11 @@ jsg::Promise<void> DurableObjectStorageOperations::setAlarm(kj::Date scheduledTi
400
397
JSG_REQUIRE (scheduledTime > kj::origin<kj::Date>(), TypeError,
401
398
" setAlarm() cannot be called with an alarm time <= 0" );
402
399
403
- JSG_REQUIRE (IoContext::current ().getActorOrThrow ().hasAlarmHandler (), TypeError,
404
- " Your Durable Object class must have an alarm() handler in order to call setAlarm()" );
400
+ // This doesn't check if we have an alarm handler per say. It checks if we have an initialized
401
+ // (post-ctor) JS durable object with an alarm handler. Notably, this means this won't throw if
402
+ // `setAlarm` is invoked in the DO ctor even if the DO class does not have an alarm handler. This
403
+ // is better than throwing even if we do have an alarm handler.
404
+ IoContext::current ().getActorOrThrow ().assertCanSetAlarm ();
405
405
406
406
auto options = configureOptions (maybeOptions.map ([](auto & o) {
407
407
return PutOptions {
@@ -470,6 +470,8 @@ kj::OneOf<jsg::Promise<bool>, jsg::Promise<int>> DurableObjectStorageOperations:
470
470
471
471
jsg::Promise<void > DurableObjectStorageOperations::deleteAlarm (
472
472
jsg::Optional<SetAlarmOptions> maybeOptions, v8::Isolate* isolate) {
473
+ // Even if we do not have an alarm handler, we might once have had one. It's fine to remove that
474
+ // alarm or noop on the absence of one.
473
475
auto options = configureOptions (maybeOptions.map ([](auto & o) {
474
476
return PutOptions {
475
477
.allowConcurrency = o.allowConcurrency ,
0 commit comments