-
Notifications
You must be signed in to change notification settings - Fork 43
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
Don't forget about context for concurrent functions #24
Comments
For example, should deriveDo and derivePipeline have context aware versions?
And how will we know that all routines are canceled |
Context seems to be a monad bundle of (State,Cancel,Timeouts) used by most Go libraries. It would be convenient to use that idiom with goderive. |
Interesting. Do you have a concrete example?
…On Mon, 18 May 2020 at 04:17, tomberek ***@***.***> wrote:
Context seems to be a monad bundle of (State,Cancel,Timeouts) used by most
Go libraries. It would be convenient to use that idiom with goderive.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YLKD3TGGHKJ5IHSATGLRSCSDHANCNFSM4DW7XTEA>
.
|
I have a few components that make grpc calls which are Context powered. The ability to cancel or to have timeouts set via Context is convenient because the rest of the Go ecosystem will propagate them through middleware nicely. |
This still sounds very interesting.
But maybe you could give an example with some go code:
- What do you have to type today.
- What do you want goderive to generate in a function.
## Some thoughts on Context
One problem I have with Context is that it doesn't enable clean shutdown.
Context sends a signal that a go routine should be shutdown, but doesn't
wait for that go routine to finish shutting down.
```go
Done() <-chan struct{}
```
Done doesn't tell you when it is done done.
I would have preferred
```go
Done() <-chan (chan struct{})
```
Then a go routine that is signalled to shutdown could also signal back to
tell the main thread, that is has completed all shutdown procedures.
But yes I get that we have to be pragmatic and go with the flow.
…On Mon, 18 May 2020 at 12:50, tomberek ***@***.***> wrote:
I have a few components that make grpc calls which are Context powered.
The ability to cancel or to have timeouts set via Context is convenient
because the rest of the Go ecosystem will propagate them through middleware
nicely.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YLMWZVSXY4RY7SC65XTRSEOKFANCNFSM4DW7XTEA>
.
|
The case have is something like this:
|
This is a great start. Okay so we read The reader of Very interesting.
Then the user can simply call this function from the method.
|
1,2. Fair point, i added that receiver/method just to get the context from somewhere, but I like your suggestion better, because the context is really describing the bind. I find myself using Curry/Uncurry with your style:
But that looks odd, not sure about the resulting syntax. It's farther from idiomatic? Or is that worth trying? (normal seems to be to make the user explicitly pass in the context: https://levelup.gitconnected.com/how-to-use-context-to-manage-your-goroutines-like-a-boss-ef1e478919e6 ) I will experiment with the: |
Example of how i am currently addressing this. This can cancel the processors, but i'm not sure if the go func's in deriveJoin become orphaned.
|
Unfortunately |
|
We need to define the generic parameter so I guess it would be"
where Then deriveFmap would need make sense and deriveJoin would need to make sense. deriveJoin would then theoretically operate on
which I don't know what it would mean with two context. |
There are two types of "Context" that may make sense to track:
My approach with the closure can better accommodate (1) while the approach with the ChanWithContext is better for handling (2). Example pipelines:
For contrast: a whole different approach is here (https://blog.gopheracademy.com/advent-2015/composable-pipelines-improvements/). |
Sorry for the late reply, I have been on holiday and then sick. derivePipeline is probably what will be used in the end. But alternatively, you can be unblocked by creating your own goderive binary, which includes your extension. |
Still using this approach
Doesn't require any changes to goderive and I use it like this:
|
Oh okay, sorry I totally misunderstood. |
@tomberek seems you are an intimate user, do you have a project that you want to link here https://github.com/awalterschulze/goderive#users ? |
Some plugins might need to pass down the context to functions that execute concurrently.
The text was updated successfully, but these errors were encountered: