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
/// Macro to simplify creating a `BoxedExecFn` compatible closure.
///
/// Takes an optional synchronous setup block and a mandatory async logic block.
/// Handles the necessary boxing (`Box::new`, `Box::pin`).
///
/// # Usage
///
/// ```ignore
/// # use turnkeeper::turnkey_job_fn; // Assuming macro is re-exported or path adjusted
/// # use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
/// # use std::time::Duration;
/// # let counter = Arc::new(AtomicUsize::new(0));
/// # let message = "Hello".to_string();
/// // With setup block:
/// let job_fn_1 = turnkey_job_fn! {
/// // Optional setup block runs immediately when outer closure is created.
/// {
/// let job_counter = counter.clone(); // Clone Arcs here
/// let local_msg = message; // Move owned data here
/// println!("Setup block executed");
/// }
/// // Main logic block (implicitly wrapped in `async move`)
/// // Captures variables defined in the setup block.
/// {
/// let count = job_counter.fetch_add(1, Ordering::SeqCst) + 1;
/// println!("Job executing (Count: {}): {}", count, local_msg);
/// tokio::time::sleep(Duration::from_millis(10)).await;
/// true // Must evaluate to bool
/// }
/// };
///
/// // Without setup block:
/// let job_fn_2 = turnkey_job_fn! {
/// // Main logic block only
/// {
/// println!("Simple job executing");
/// tokio::time::sleep(Duration::from_millis(5)).await;
/// true
/// }
/// };
/// # let scheduler: turnkeeper::TurnKeeper = todo!(); // Placeholder for example
/// # let request: turnkeeper::job::TKJobRequest = todo!(); // Placeholder
/// # tokio_test::block_on(scheduler.add_job_async(request.clone(), job_fn_1));
/// # tokio_test::block_on(scheduler.add_job_async(request, job_fn_2));
/// ```
;
Boxpin as Pin
}
};
// Matcher 2: Only the main logic block is provided
=> ;
}