summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/cron/01_cron.ts23
-rw-r--r--ext/cron/local.rs7
2 files changed, 25 insertions, 5 deletions
diff --git a/ext/cron/01_cron.ts b/ext/cron/01_cron.ts
index a615ae34b..30343905c 100644
--- a/ext/cron/01_cron.ts
+++ b/ext/cron/01_cron.ts
@@ -6,8 +6,12 @@ const core = Deno.core;
function cron(
name: string,
schedule: string,
- handler: () => Promise<void> | void,
- options?: { backoffSchedule?: number[]; signal?: AbortSignal },
+ handlerOrOptions1:
+ | (() => Promise<void> | void)
+ | ({ backoffSchedule?: number[]; signal?: AbortSignal }),
+ handlerOrOptions2?:
+ | (() => Promise<void> | void)
+ | ({ backoffSchedule?: number[]; signal?: AbortSignal }),
) {
if (name === undefined) {
throw new TypeError("Deno.cron requires a unique name");
@@ -15,7 +19,20 @@ function cron(
if (schedule === undefined) {
throw new TypeError("Deno.cron requires a valid schedule");
}
- if (handler === undefined) {
+
+ let handler: () => Promise<void> | void;
+ let options: { backoffSchedule?: number[]; signal?: AbortSignal } | undefined;
+
+ if (typeof handlerOrOptions1 === "function") {
+ handler = handlerOrOptions1;
+ if (typeof handlerOrOptions2 === "function") {
+ throw new TypeError("options must be an object");
+ }
+ options = handlerOrOptions2;
+ } else if (typeof handlerOrOptions2 === "function") {
+ handler = handlerOrOptions2;
+ options = handlerOrOptions1;
+ } else {
throw new TypeError("Deno.cron requires a handler");
}
diff --git a/ext/cron/local.rs b/ext/cron/local.rs
index 0b6dcae2e..5f1ace6d1 100644
--- a/ext/cron/local.rs
+++ b/ext/cron/local.rs
@@ -174,8 +174,11 @@ impl RuntimeState {
.map(move |name| (*ts, name.clone()))
.collect::<Vec<_>>()
})
- .map(|(_, name)| {
- (name.clone(), self.crons.get(&name).unwrap().next_tx.clone())
+ .filter_map(|(_, name)| {
+ self
+ .crons
+ .get(&name)
+ .map(|c| (name.clone(), c.next_tx.clone()))
})
.collect::<Vec<_>>()
};