-
Notifications
You must be signed in to change notification settings - Fork 14
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
Dependency context.Context #31
Conversation
The following reworks the dependency engine to bring in a real context.Context. The fallout of this means that we decouple the concept of cancelation and where you get the dependency from. In doing so, context has become snapshot. The original comments around this type just state that it is a snapshot, so we might as well just call it that. The dependency Context becomes split. Removing the cross cutting concerns. The aborting of a worker in the start now becomes context.Context and the retrival of a dependency is now a Container. Currently we're just creating a adhoc context.Context, but in the next commit, we'll tie this to the tomb directly, ensuring that upon destruction of the engine, all manifolds will be killed.
The context creation is now tied to the lifecycle of the tomb. Doing this ensures that when the engine is killed, then the context is also killed. It worth noting that cancel is idempotent so, calling it multiple times does nothing. As the main loop on tomb death is also attempting to cancel the context of the snapshot worker, it essentially becomes a no-op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I like the replacement of dependency.Context with dependency.Container.
what about:
dependency.Getter
dependency.Dependencies
dependency.Others
dependency.Snapshot
?
// the tomb. | ||
func (engine *Engine) scopedContext() (context.Context, context.CancelFunc) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
return engine.tomb.Context(ctx), cancel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reading the engine.tomb.Context() documentation, wouldn't it make more sense to just use engine.tomb.Context() ?
I guess you're trying to get access to its cancel function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
Renaming Container (DI) to Getter to prevent any confusion over what a container is in this context.
This is a breaking change, so we should bump from v3 to v4.
/merge |
The following reworks the dependency engine to bring in a real
context.Context. The fallout of this means that we decouple the
concept of cancelation and where you get the dependency from. In
doing so, context has become snapshot. The original comments
around this type just state that it is a snapshot, so we might as
well just call it that.
The dependency Context becomes split. Removing the cross-cutting
concerns. The aborting of a worker in the start now becomes
context.Context and the retrieval of a dependency are now a Container.
The context creation is now tied to the lifecycle of the tomb. Doing
this ensures that when the engine is killed, then the context is also
killed. It is worth noting that cancel is idempotent so, calling it multiple
times does nothing after the first call (unlike channels). As the main
loop on tomb death is also attempting to cancel the context of the
snapshot worker, it essentially becomes a no-op.
JUJU-4623