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

Add context to Event method, callback handlers and canceling an event #82

Merged
merged 4 commits into from
Jul 26, 2022

Conversation

annismckenzie
Copy link
Contributor

@annismckenzie annismckenzie commented Dec 23, 2021

This PR adds a context to the main Event method. It's also in response to #37 (comment). Finally, it's the first step towards implementing #43 and #38.

Adding the context is a breaking change and while the library isn't at v1.0.0 yet it's still an inconvenience. I distinctly didn't add a CallbacksContext field because of the following reasons:

  • while an inconvenience, it's easy to add the context to all callback functions – even the way I did in the test suite using _ context.Context
  • it'd make the internal logic fragile
  • it's now best practice to have a context available, especially given the fact that the library supports asynchronous transitions and be able to cancel work that isn't needed anymore

Of course, if the maintainer(s)/contributors/the community at large wants this then it's still totally possible.

To see the whole thing in action, potential users can use the full implementation: alfaview#1 (this PR only contains the first part).

event.go Show resolved Hide resolved
@maxekman
Copy link
Member

Nice work! I’ll review this after the holidays.

@serg-kovalev
Copy link

@maxekman Hi! can you review it please? seems to be it's a good piece of functionality

@maxekman
Copy link
Member

Yes! Sorry, totally forgot about this as I changed jobs this spring. There is some work going on with a generics version, that would be v2 if we merge it. Maybe this change can mark the v1 of the lib?

Please rebase this also, thanks.

@maxekman
Copy link
Member

Looks good on a quick read. Maybe add an example for utilizing the context?

@lzecca78
Copy link

I am looking forward to this feature! I really need this 🚀

@annismckenzie
Copy link
Contributor Author

So sorry, I'll get to this this week (and rebase as well).

@maxekman
Copy link
Member

No stress! Your contribution is much appreciated!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 93.622% when pulling d0046a7 on alfaview:contextify-fsm into 13de56e on looplab:main.

@annismckenzie
Copy link
Contributor Author

Looks good on a quick read. Maybe add an example for utilizing the context?

I tried to do that yesterday but all the examples I came up with are somehow contrived and not useful yet because this is only a preparation MR so I can pull in the rest that's contained in alfaview#1. Would it be okay to merge as is? The rebase is done.

@maxekman
Copy link
Member

Sure! Let’s do it in that order.

@maxekman maxekman merged commit 54bbb61 into looplab:main Jul 26, 2022
@maxekman
Copy link
Member

Thanks for picking this up again and contributing!

@maxekman
Copy link
Member

Let’s do a 1.0 release after your other PR is in. Great push!

@serg-kovalev
Copy link

Hooray! thanks @annismckenzie @maxekman

@maxekman maxekman mentioned this pull request Jul 27, 2022
@annismckenzie annismckenzie deleted the contextify-fsm branch July 29, 2022 14:07
@annismckenzie
Copy link
Contributor Author

The second part of this is up: #88.

guilhem-barthes added a commit to Substra/orchestrator that referenced this pull request Jan 18, 2023
## Description

Between v0.3.0 and v1.0.0 (more precisely in
looplab/fsm#82), the authors of fsm introduced a
new first parameter of type`context.Context` in `Callback`, `Event` and
other structures. This PR:

- Create a wrapper that discard the first argument and call our
callbacks
- Add a blank Context
([Background()](https://pkg.go.dev/context#Background)) to all the event
we create

## How has this been tested?

CI

## Checklist

- [x] [changelog](../CHANGELOG.md) was updated with notable changes
- [ ] documentation was updated

Signed-off-by: Guilhem Barthes <guilhem.barthes@owkin.com>
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 this pull request may close these issues.

None yet

5 participants