diff options
author | Igor Zinkovsky <igor@deno.com> | 2023-11-16 14:19:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 14:19:00 -0800 |
commit | b572abfcb3fadbfdd3ce671a27463d67bcb77534 (patch) | |
tree | a3b783218079b01b16a331f7522d3a3935603520 /ext/cron/local.rs | |
parent | 6b42cecc064d01d87aae978ecd7eb372bfe9a34e (diff) |
feat(ext/cron) modify Deno.cron API to make handler arg last (#21225)
This PR changes the `Deno.cron` API:
* Marks the existing function as deprecated
* Introduces 2 new overloads, where the handler arg is always last:
```ts
Deno.cron(
name: string,
schedule: string,
handler: () => Promise<void> | void,
)
Deno.cron(
name: string,
schedule: string,
options?: { backoffSchedule?: number[]; signal?: AbortSignal },
handler: () => Promise<void> | void,
)
```
This PR also fixes a bug, when other crons continue execution after one
of the crons was closed using `signal`.
Diffstat (limited to 'ext/cron/local.rs')
-rw-r--r-- | ext/cron/local.rs | 7 |
1 files changed, 5 insertions, 2 deletions
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<_>>() }; |