experimental: adds close notification hook (#1574)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
27
experimental/close_example_test.go
Normal file
27
experimental/close_example_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package experimental_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental"
|
||||
)
|
||||
|
||||
var ctx context.Context
|
||||
|
||||
// This shows how to implement a custom cleanup task on close.
|
||||
func Example_closeNotifier() {
|
||||
closeCh := make(chan struct{})
|
||||
ctx = experimental.WithCloseNotifier(
|
||||
ctx,
|
||||
experimental.CloseNotifyFunc(func(context.Context, uint32) { close(closeCh) }),
|
||||
)
|
||||
|
||||
// ... create module, do some work. Sometime later in another goroutine:
|
||||
|
||||
select {
|
||||
case <-closeCh:
|
||||
// do some cleanup
|
||||
default:
|
||||
// do some more work with the module
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user