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

Change WorkFunction to anonymous function #6

Open
akamensky opened this issue Nov 14, 2021 · 4 comments · May be fixed by #7
Open

Change WorkFunction to anonymous function #6

akamensky opened this issue Nov 14, 2021 · 4 comments · May be fixed by #7

Comments

@akamensky
Copy link

Is your feature request related to a problem? Please describe.
Since this is right now declared as an interface with a single Run() method I am unable to pass any other variables as part of context.

Describe the solution you'd like
Using anonymous function instead of interface we don't need to declare any new types and are able to use execution context. Such as (from the example code):

func main() {
        // init some external client
        c := client.New(...)
	max := 10
	inputChan := make(chan concurrently.WorkFunction)
	output := concurrently.Process(inputChan, &concurrently.Options{PoolSize: 10, OutChannelBuffer: 10})
	go func() {
		for work := 0; work < max; work++ {
			inputChan <- func() interface{} {
				// do some work using client
				result := c.DoWork(work)
				return result
			}
		}
		close(inputChan)
	}()
	for out := range output {
		log.Println(out.Value)
	}
}

Describe alternatives you've considered
N/A

Additional context
N/A

@akamensky akamensky linked a pull request Nov 14, 2021 that will close this issue
@akamensky
Copy link
Author

I provided an changeset for this. The code change is minimal, mostly changes are in tests.

However I'd suggest to not merge it as-is to v2.0.0 because this will break compatibility for those using this library

@tejzpr
Copy link
Owner

tejzpr commented Nov 22, 2021

v3.0.0 adds support for passing a context, please check if this satisfies your requirement.

@akamensky
Copy link
Author

It doesn't. Instantiating a new type object doesn't allow for this whatsoever. Contexts semantically are not for passing variables. And there are way more flexibility with anonymous functions than with context.

fholzer added a commit to fholzer/ordered-concurrently that referenced this issue Oct 1, 2022
fholzer added a commit to fholzer/ordered-concurrently that referenced this issue Oct 1, 2022
fholzer added a commit to fholzer/ordered-concurrently that referenced this issue Oct 1, 2022
@ricardobranco777
Copy link

I manage to pass more variables like this:

https://github.com/ricardobranco777/regview/blob/master/print.go#L18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants