1 | void log_response(int reqest_response) { |
2 | // fake logging logic |
3 | } |
4 | |
5 | int slow_handle_request(int id) { |
6 | // "slow" request handling logic |
7 | for (int i = 0; i < 10; i++) |
8 | id += 2; |
9 | return id; |
10 | } |
11 | |
12 | int fast_handle_request(int id) { |
13 | // "fast" request handling logic |
14 | return id + 2; |
15 | } |
16 | |
17 | void iterative_handle_request_by_id(int id, int reps) { |
18 | int response; |
19 | for (int i = 0; i < reps; i++) { |
20 | if (i % 2 == 0) |
21 | response = fast_handle_request(id); |
22 | else |
23 | response = slow_handle_request(id); |
24 | log_response(reqest_response: response); |
25 | } |
26 | } |
27 | |
28 | int main() { |
29 | int n_requests = 10; |
30 | for (int id = 0; id < n_requests; id++) { |
31 | iterative_handle_request_by_id(id, reps: 3); |
32 | } |
33 | return 0; |
34 | } |
35 | |