Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SetRunner option #294

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions connection_onevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (

var runTask = gopool.CtxGo

func setRunner(runner func(ctx context.Context, f func())) {
runTask = runner
}

func disableGopool() error {
runTask = func(ctx context.Context, f func()) {
go f()
Expand Down
6 changes: 6 additions & 0 deletions netpoll_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package netpoll

import (
"context"
"io"
"time"
)
Expand Down Expand Up @@ -48,6 +49,11 @@ func SetLoggerOutput(w io.Writer) {
setLoggerOutput(w)
}

// SetRunner set the runner function for every OnRequest/OnConnect callback
func SetRunner(f func(ctx context.Context, f func())) {
setRunner(f)
}

// DisableGopool will remove gopool(the goroutine pool used to run OnRequest),
// which means that OnRequest will be run via `go OnRequest(...)`.
// Usually, OnRequest will cause stack expansion, which can be solved by reusing goroutine.
Expand Down
Loading