-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On receiving an interrupt signal, mage cancels the context allowing the magefile to perform any cleanup before exiting. A second interrupt signal will kill the magefile process without delay. The behaviour for a timeout remains unchanged (context is canclled and the magefile exits).
- Loading branch information
1 parent
707b7bd
commit 0aa93f8
Showing
4 changed files
with
172 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//+build mage | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
// Exits after receiving SIGHUP | ||
func ExitsAfterSighup(ctx context.Context) { | ||
sigC := make(chan os.Signal, 1) | ||
signal.Notify(sigC, syscall.SIGHUP) | ||
<-sigC | ||
fmt.Println("received sighup") | ||
} | ||
|
||
// Exits after SIGINT and wait | ||
func ExitsAfterSigint(ctx context.Context) { | ||
sigC := make(chan os.Signal, 1) | ||
signal.Notify(sigC, syscall.SIGINT) | ||
<-sigC | ||
fmt.Printf("exiting...") | ||
time.Sleep(200 * time.Millisecond) | ||
fmt.Println("done") | ||
} | ||
|
||
// Exits after ctx cancel and wait | ||
func ExitsAfterCancel(ctx context.Context) { | ||
<-ctx.Done() | ||
fmt.Printf("exiting...") | ||
time.Sleep(200 * time.Millisecond) | ||
fmt.Println("done") | ||
} | ||
|
||
// Ignores all signals, requires killing | ||
func IgnoresSignals(ctx context.Context) { | ||
sigC := make(chan os.Signal, 1) | ||
signal.Notify(sigC, syscall.SIGINT) | ||
for { | ||
<-sigC | ||
} | ||
} |