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

Async actions #62

Merged
merged 6 commits into from
Nov 18, 2019
Merged

Async actions #62

merged 6 commits into from
Nov 18, 2019

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Nov 17, 2019

Closes #28.

This PR adds first-class support for asynchronous actions (i.e. non-blocking background work) leveraging the recently stabilized futures! 🎉

A Command can be handed to the runtime for execution. As the futures comprising it finish, the produced messages will be handed back to Application::update.

The todos example has been improved to showcase this feature. Now, it automatically saves and loads its state using serde_json.

Changelog

Added

  • Command<T>, which represents a batch of futures producing a result of type T.
  • Application::new, which must return a (Self, Command<Message>). This allows applications to perform an async action at startup.

Changed

  • Application::update now must return a Command<Message>. Command::none can be used if no async action is needed.
  • Application::run is a static method now, thanks to the new Application::new method.

@hecrj hecrj added the feature New feature or request label Nov 17, 2019
@hecrj hecrj added this to the 0.1.0 milestone Nov 17, 2019
@hecrj hecrj self-assigned this Nov 17, 2019
@daxpedda
Copy link
Contributor

daxpedda commented Nov 18, 2019

I see that you used ThreadPool as the executor. Would you consider making this only the default but allowing to pass a different executor with the help of futures::task::Spawn?

That way a user can implement his own executor or use libraries that support Spawn, hopefully tokio or async-std at some point.

Happy to make a PR for this if you approve.

@hecrj
Copy link
Member Author

hecrj commented Nov 18, 2019

Hey @daxpedda, thanks for taking a look!

That way a user can implement his own executor or use libraries that support Spawn, hopefully tokio or async-std at some point.

What would be the use cases for this?

@hecrj hecrj merged commit 5adefdf into master Nov 18, 2019
@hecrj hecrj deleted the feature/async-actions branch November 18, 2019 22:06
@hecrj
Copy link
Member Author

hecrj commented Nov 18, 2019

@daxpedda I have created a new issue referencing your comment in #63. We can keep discussing things there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async actions
2 participants