-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Getting current worker number #88
Comments
Hi @ahmafi! |
Hi, I'm spawning a headless chrome in each pool and I wanted to save the chrome |
Oh, I see. IMO your use case could benefit from a import (
"sync"
"github.com/alitto/pond/v2"
)
func main() {
var userDataDirPool = sync.Pool{
New: func() any {
// Create a new user data dir in a random location
return newDir
},
}
// Create a pool with a max concurrency of 10
pool := pond.NewPool(10)
defer pool.StopAndWait()
// Submit several concurrent tasks
for i := 0; i < 1000; i++ {
pool.Submit(func() {
// Get a dir from the pool (it may be a new one or reused)
userDataDir := userDataDirPool.Get().(string)
// Optionally, clean up the user data dir in case some of its contents cannot be reused
// cleanupDir(userDataDir)
// Launch chrome process using the obtained userDataDir
launchChromeProcess(userDataDir)
// Return the user data dir to the pool
userDataDirPool.Put(userDataDir)
})
}
} The max concurrency limit on |
Are there any ids or index numbers assigned to workers? I want to pass the worker number to the
Submit
function.The text was updated successfully, but these errors were encountered: