Oct 6, 2023
Depends on what type of timeout you need but
I made one of the timeout approaches.
This approach raises cancel of the current task by timeout occurring and moving forward discarding awaiting the task.
Canceling tasks is not actually stopping current operations it’s just fact that telling them it’s canceled.
Below code calling cancel to task but “done” print will be done after longOperation has been finished except the operation has handling for cancel.
So let’s imagine the following case
This case needs a timeout for fetching the flag in 5sec in any case.
Whether raising canceling makes actually stop the current operation and pop out their step is up to the implementation.
To make timeout anyway at all costs of discarding handling them.
(So actually fetch request is still ongoing but moving forward anyway because it’s timed out.)
To achieve this behavior needs to harness unstructured concurrency API inside.