go-execute icon indicating copy to clipboard operation
go-execute copied to clipboard

WIP: Implement cancellation via context

Open alexellis opened this issue 4 years ago • 1 comments

Signed-off-by: Alex Ellis (OpenFaaS Ltd) [email protected]

Description

WIP: Implement cancellation via context

Execute allows a user to pass in a context with a timeout, or a cancellation that can be used to terminate the process.

Fixes: #10 #9

How Has This Been Tested?

Tested with a couple of scenarios:

  • TestExecuteWithContext_SleepInterruptedByTimeout - shows that a sleep process gets aborted due to a timeout
  • TestExecuteWithContext_SleepWithinTimeout - shows that a sleep can pass with a deadline, that's generous enough for it.
  • TestExecuteWithContext_Shell_BackgroundPrintsToStdout - uses a context, but doesn't set any kind of limits or cancellation - shows that the happy path still works as before

How are existing users impacted? What migration steps/scripts do we need?

Existing users must update their code to include context.TODO() or context.Background().

Checklist:

Docs to be updated once solution is refined for merge.

alexellis avatar Apr 17 '22 08:04 alexellis

@josegonzalez feel free to try this out

To handle signals, use the code like: https://gobyexample.com/signals

With a context.WithCancel, then call the cancel() function after sig := <-sigs

alexellis avatar Apr 17 '22 09:04 alexellis