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 an extra ergonomic method for n2c chainsync #439

Merged
merged 3 commits into from
Apr 16, 2024

Conversation

Quantumplation
Copy link
Collaborator

When actually consuming the chainsync client, initially the consumer
should call request_next repeatedly. However, once you are caught up,
you will get an "Await" response, which says we've requested the next
block, but the server doesn't have one for us, and will let us know when
one is available. If we request_next again, it fails.

In fact, even the example was misleading in this way!

The correct way to consume it was to check if you have agency, and if
so, either await or recieve.

If you tried to do this, though, especially when mixing it with other
future things (like select! on a cancellation token), then things could
get messy, because even though they return the same type, the impl
Future instances were opaque to the compiler.

This convenience method makes it nice and simple to idiomatically just
consume the next block as appropriate, and plays well with select!

When actually consuming the chainsync client, initially the consumer
should call request_next repeatedly. However, once you are caught up,
you will get an "Await" response, which says we've requested the next
block, but the server doesn't have one for us, and will let us know when
one is available. If we request_next again, it fails.

In fact, even the example was misleading in this way!

The correct way to consume it was to check if you have agency, and if
so, either await or recieve.

If you tried to do this, though, especially when mixing it with other
future things (like select! on a cancellation token), then things could
get messy, because even though they return the same type, the impl
Future instances were opaque to the compiler.

This convenience method makes it nice and simple to idiomatically just
consume the next block as appropriate, and plays well with select!
Rebased, and this type has been updated since
@scarmuega scarmuega merged commit 1724f6a into main Apr 16, 2024
5 checks passed
@scarmuega scarmuega deleted the pi/ergonomic-chainsync branch April 16, 2024 22:04
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.

2 participants