experimental: adds close notification hook (#1574)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-07-11 09:27:43 +08:00
committed by GitHub
parent 326c267726
commit 0300f4b3c1
10 changed files with 201 additions and 50 deletions

View 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
}
}