Add context.Context Support and Improve Context Handling in Stream Methods#341
Open
molon wants to merge 14 commits intoalpacahq:masterfrom
Open
Add context.Context Support and Improve Context Handling in Stream Methods#341molon wants to merge 14 commits intoalpacahq:masterfrom
molon wants to merge 14 commits intoalpacahq:masterfrom
Conversation
- All `rest` methods provide `ctx` support - The `ctx` of the `Connect` method is only used as `initialCtx`. If you want to cancel the connection, please use the `Terminate` method - Change `time.Sleep` to `ctxtime.Sleep` to ensure timely cancellation - Remove the default timeout of `handleSubChange`, uniformly controlled by `ctx`, and give `subChangeRequest.result` a `buffer` to prevent deadlock caused by `handleSubChange` error return in extreme cases.
…oncurrency support - Updated bull-spread example to pass context in API calls. - Modified internal sleep function to handle nil context gracefully. - Refactored marketdata functions to include context for better request management. - Ensured all relevant functions in marketdata package now accept context as a parameter.
- Moved ctxtime import to maintain consistency across files. - Updated error wrapping in maintainConnection function for better error context.
…g and logging - Updated timeout durations in TestSubscriptionTimeout for better clarity. - Replaced log statements with log.Println for consistency. - Refactored context handling in TestSubscriptionTwiceAcrossConnectionIssues. - Ensured proper cancellation of contexts in relevant test cases.
…r better resource management - Updated Connect methods in various clients to return a termination function alongside error handling. - Enhanced StreamTradeUpdatesInBackground to provide a terminate function for stopping the stream. - Improved context handling in examples to ensure proper termination of connections.
Collaborator
|
@molon This is a giant backward incompatible change. There are two ways to get this merged:
|
Author
|
Sorry for the late reply. I prefer the first way. Additionally, I'm debating one issue. |
zeldahack
approved these changes
Aug 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
restmethods now provide propercontext.ContextsupportConnectmethod,ctxonly controls the initial connection process, not the full stream lifecycleConnect, use the returnedterminatefunction or theTerminatemethodStreamTradeUpdatesInBackground,ctxonly controls the initial connection, stream continues running independently afterwardStreamTradeUpdatesInBackground, use the returnedterminatefunctiontime.Sleepwithctxtime.Sleepto ensure timely cancellation on context expirationhandleSubChange, now uniformly controlled byctxsubChangeRequest.resultto prevent deadlocks caused byhandleSubChangeerror returns in edge casesThese changes improve context handling throughout the API, making resource management more predictable and preventing potential deadlocks.