Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

sdk/agent: implement event handling with channels #257

Merged
merged 50 commits into from
Aug 27, 2021

Conversation

leighmcculloch
Copy link
Contributor

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.

@leighmcculloch leighmcculloch marked this pull request as ready for review August 26, 2021 22:13
Base automatically changed from firsttest to main August 27, 2021 15:54
@leighmcculloch leighmcculloch enabled auto-merge (squash) August 27, 2021 22:22
@leighmcculloch leighmcculloch linked an issue Aug 27, 2021 that may be closed by this pull request
Copy link
Contributor

@acharb acharb left a 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)
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

sdk/agent/events.go Outdated Show resolved Hide resolved
sdk/agent/events.go Show resolved Hide resolved
@leighmcculloch leighmcculloch merged commit 48ed2c3 into main Aug 27, 2021
Copy link
Contributor

@acharb acharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@leighmcculloch leighmcculloch deleted the issue226-channels branch August 27, 2021 23:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sdk/agent: add event handlers for open, payment, close
2 participants