-
Notifications
You must be signed in to change notification settings - Fork 513
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
Tracking ACKs for published events; Futures API #1144
Merged
Merged
Conversation
This file contains 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
…ime; minor renamings
sergeuz
force-pushed
the
feature/usb_logging_1_of_2
branch
from
October 29, 2016 20:01
b1d7d74
to
7d404a8
Compare
Conflicts resolved: user/inc/application.h user/tests/unit/makefile
7 tasks
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.
This PR implements a generic approach for handling results of asynchronous operations in user space (via Futures), and also implements tracking of acknowledgements for published events, so that user can have a guarantee that published event was actually received by the server. Beginning of the discussion can be found here: #1034.
Futures API
Future
is a handle for an asynchronous operation. It's possible to poll future's state, wait on future synchronously, or register a callback that will be invoked when operation completes (either successfully or with an error).For example:
Internally, futures are created via
Promise
objects, which in turn are created separately for each operation that needs to be processed asynchronously (if we want to expose result of such operation to user). One can think of the promises and futures as write-only and read-only interfaces for accessing result of an operation. Trivial example:Promise
can be passed to a system function in the following way:completion_callback
is a generic callback type for completion handling within the system (declared here).Promise
provides built-in implementation of this callback, which can be used for simple result types that don't require ABI compatibility checks.There's also convenience wrapper class named
CompletionHandler
, which acts as a smart pointer for raw completion callbacks and provides a guarantee that a callback will be always invoked with some result or error:Publishing events with confirmation
Particle.publish()
was updated to returnFuture<void>
. Additionally,WITH_ACK
flag was added to instruct the protocol implementation that caller wants to confirm receiving of an event at the server side. IfParticle.publish()
is invoked withoutWITH_ACK
flag, returned future will be set to completed state after sending event message to the server and without waiting for corresponding ACK message.Test application:
Possible logging output (debug build):
On both Photon and Electron, sending of the second event should finish only after receiving ACK for corresponding event message.
Note that this branch is based on
feature/usb_logging_1_of_2
branch that introducesVector
container.Doneness:
Features
WITH_ACK
flag forParticle.publish()
) [PR #1144]