Documentation
¶
Overview ¶
Example (Aware_exit) ¶
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"chainguard.dev/exitdir"
)
func main() {
tempdir, err := os.MkdirTemp(os.TempDir(), "example_aware_exit*")
if err != nil {
log.Fatal(err)
}
defer os.Remove(tempdir)
if err := os.Setenv("EXIT_DIR", tempdir); err != nil {
panic(err)
}
time.Sleep(1 * time.Millisecond)
go func() {
ctx := exitdir.Aware(context.Background())
ticker := time.NewTicker(5 * time.Millisecond)
for i := 0; true; i++ {
select {
case <-ctx.Done():
fmt.Println("[Follower] Exiting...")
return
case <-ticker.C:
fmt.Println("[Follower] Tick", i)
}
}
}()
fmt.Println("[Leader] Doing work...")
time.Sleep(13 * time.Millisecond)
fmt.Println("[Leader] Exiting...")
if err := exitdir.Exit(); err != nil {
panic(err)
}
time.Sleep(1 * time.Millisecond)
}
Output: [Leader] Doing work... [Follower] Tick 0 [Follower] Tick 1 [Leader] Exiting... [Follower] Exiting...
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.