-
Notifications
You must be signed in to change notification settings - Fork 3
Using Futures
ARn edited this page May 8, 2016
·
2 revisions
Playing with actors to achieve concurrency is almost straightforward once you get in the habit of exposing behaviors and sending messages from actors to actors. Difficulties may arise at the point your code need to leave the actor world to get back to the non actor world : typically, you want to display your data on a WPF or a Form or on a WebPage, and this part is not an actor.
Future can be used as a pattern to solve this :
- cast a Future of the expected return type
Future<string> - Futures are actors too, so use this future to receive message from other actors
- Use in non-actor code the future to receive the expected data
- Blocking way :
future.GetResult() ; - Non-blocking :
await future.GetResultAsync()
Some samples application use this pattern : look at the WebQuote sample application for usage.