1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Background work collector for `waitUntil`-style tasks.
//!
//! This mirrors the behavior of the Node.js runtime's `Awaiter`
//! (`packages/node/src/awaiter.ts`). Crucially, `waitUntil` is implemented
//! entirely in-process: there is **no** dedicated IPC message. The per-request
//! `end` IPC message is sent immediately after the handler responds and is
//! **never** delayed by background work. Registered futures are drained only at
//! process shutdown (SIGTERM). In production the drain is unbounded (background
//! work runs until it resolves or the function times out); in `vc dev` it is
//! bounded by [`WAIT_UNTIL_TIMEOUT`] so a hung task cannot keep the dev process
//! alive.
//!
//! Like the Node implementation:
//! - A future registered via [`Awaiter::wait_until`] runs regardless of whether
//! the originating handler succeeded or errored.
//! - Errors/panics in a background future are swallowed (logged) and never abort
//! the drain or affect other background work (the analog of `.catch(onError)`).
//! - The drain loops until the set is empty so futures that schedule further
//! `wait_until` work are also awaited (the analog of the two-batch drain).
use Future;
use ;
use JoinHandle;
/// Time (in seconds) to wait for background work to finish at shutdown before
/// giving up. Only applied in `vc dev`; production drains are unbounded. Matches
/// the `WAIT_UNTIL_TIMEOUT` dev fallback in `@vercel/node`.
pub const WAIT_UNTIL_TIMEOUT: u64 = 30;
/// Collects background futures registered via `waitUntil` and drains them at
/// shutdown. Cheaply cloneable; all clones share the same underlying task set.