-
Notifications
You must be signed in to change notification settings - Fork 94
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 support for context.Context #231
Conversation
Codecov Report
@@ Coverage Diff @@
## master #231 +/- ##
==========================================
- Coverage 61.34% 61.18% -0.16%
==========================================
Files 68 68
Lines 6327 6351 +24
==========================================
+ Hits 3881 3886 +5
- Misses 1933 1949 +16
- Partials 513 516 +3
Continue to review full report at Codecov.
|
I know the PR is still a draft but since it contains pretty heavy changes I'd like to comment now to prevent you from doing unnecessary work if we agree on a different path. Basically, I would like to avoid context pollution where it is not necessary. IMO the benefit of context in the case of Genji is essentially for canceling anything that relies on IO, even indirectly. Some APIs are designed to be one time in-memory procedures. For these, handling cancelation from within the function is the same as handling it from outside, so passing the context is not necessary. Even on IO related APIs, I believe we can avoid context pollution by having some indirection. For example, instead of passing the context to any engine/store method, we could pass it only to the Concerning the document.Iterator type, it is returned as a result of |
Thanks for the input! I agree on the context pollution issue, but I’d rather avoid indirection as it doesn’t add much value since you either already have In Genji we can have the root
Here, The reason why |
Regarding
|
@asdine I’ll update this PR to conform with the RFC001 and mark it as ready then. Let me know if you want this in a separate PR though. |
@tie Let's start over on a separate PR if you don't mind |
Sure! |
This PR adds
context.Context
support in Genji, starting with theengine
package and then fixing compile errors everywhere. It doesn’t introduce any cancellation behavior though—that should be a separate, smaller, PR.engine.Iterator
usage now requires ait.Err()
check after the loop.Notice that
Seek
andNext
now accept acontext.Context
parameter. If an error occurs,Valid
returns false.database.Table
no longer directly implementsdocument.Iterator
since iteration may be I/O bound.Closes #224 and #206