Skip to content

Store variables per worker #106

@Azer0s

Description

@Azer0s

I was wondering if there was any built-in way of storing data per worker (e.g. TCP connections) and retrieve them in a task.
Something like this:

// Create a pool with limited concurrency
pool := pond.NewPool(100)

// Submit 1000 tasks
for i := 0; i < 1000; i++ {
	i := i
	pool.Submit(func(wc pond.WorkerContext) {
                t, ok := wc.Get("worker")
                if !ok {
                        t = i
                        wc.Set("worker, i)
                }

		fmt.Printf("Running task #%d in worker #%d\n", i, t)
	})
}

I don't know a lot about pond but I think such a feature would be quite cool

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions