-
Notifications
You must be signed in to change notification settings - Fork 9
sdk/agent: implement event handling with channels #257
Conversation
This reverts commit f8743b4.
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.
lgtm 👍 had a question and some thoughts, none blocking but wanted to see your thoughts on the ❓ before approving
@@ -103,6 +103,27 @@ func run() error { | |||
FeeAccount: accountKey, | |||
FeeAccountSigners: []*keypair.Full{signerKey}, | |||
} | |||
events := make(chan agent.Event) |
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.
💡 thoughts on adding a "poll" command to the example similar to as you described in the description:
They can simply use a buffered channel and poll when they want to.
I think logging doesn't show the power of this events channel. But being able to poll on command the events could simulate what a user might do
wouldn't be in this PR though, just an idea that popped into my head
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.
going to approve since this would be in a separate PR if we decided to do
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.
We could have some example tests for sure that demonstrate different methods of use.
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.
lgtm!
What
Add event handlers for the things that can occur in the background during open, payment, and close.
Why
The agent receives messages from the other participant containing confirmations/responses to requests made by this recipient, and requests from the other participant. Some of these operations that take place in the background need to be made known to the application using the agent.
The agent will also monitor the state of the network for changes that require action, and once that logic is added we'll need to add events using the same pattern.
A channel is used for delivering these background events because it makes it easier for developers who don't want to handle concurrent routines in their code. They can simply use a buffered channel and poll when they want to. Or they can put it in a go routine and trigger any functions they have for each.
Supersedes #242
Close #226
Known Limitations
This change is somewhat limited because some of the change depends on ingestion having been integrated into the agent, but I'm deferring doing that integration until the integration and state changes have been finished in the state package. Because of that there are some TODOs, but I think it is worth merging this and revisiting it during the ingestion work.