forked from near/nearcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TestLoop] Make MessageWithCallback accept future as a result. (near#…
…12212) Previously, `MessageWithCallback<T, R>` contains `T` as well as a callback that is a function that accepts an `Result<R, AsyncSendError>`. And then, `AsyncSender<T, R>` is simply `Sender<MessageWithCallback<T, R>>`. The problem was that in the actix implementation of `Sender<MessageWithCallback<T, R>>`, because on the actix side when we call `.send(msg)` it gives us a future of `R`, we cannot call the callback right away. The solution was to `actix::spawn` a future that awaits this future of `R` and then we call the callback. This was a bad design, because it is actually the *sender* (code that calls `.send_async(...)`) who ends up calling `actix::spawn`, and that panics if the sender was not on an actix thread. This PR changes that so that `MessageWithCallback<T, R>` contains a callback that accepts a future of the result. That way, it becomes the responsibility of whoever awaits on the resulting future from `.send_async(...)` to drive the result future, and there won't be any problems since we don't spawn anything anymore. Also correct a use case where code in the test was sending a custom MessageWithCallback. This is not supported; changed it to spawning a future on the testloop instead.
- Loading branch information
1 parent
8cfa7a7
commit e0d9637
Showing
10 changed files
with
71 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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