-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Problem:
Send command and observe resulting events via subscription.
Solution:
// Create subscription before command
var subscription = client
.subscribeToEvents<Event>()
.post();
subscription.eventMessages.forEach((event) {
....
<some event reaction here>
....
})
/// Now when we have a subscription let's send the command.
client.command(commandMessage)
Expectations:
We receive Event
Actual behavior:
Sometimes we receive Event.
Reasoning:
subscribeToEvents.post is async by design and by Javadoc, but doesn't async by the method signature.
To make above example work. Following solution should be used:
var plannedSubscription = client
.subscribeToEvents<Event>()
.post();
// Await for internal Future<Subscription> to resolve so subscription is actually created
plannedSubscription.subsciption.then((ignored) => client.command(commandMessage));
It's an unclear API and it's difficult to use it, especially when you want to have several subscriptions active before command send.
Consider rewriting of .post method API to post(...) async so the developer is forced to decide either it's important for him to resolve this future right now or not.
Metadata
Metadata
Assignees
Labels
No labels