From 77259b80f536246e30731c1a2e57f7bc7f8fe391 Mon Sep 17 00:00:00 2001 From: James Ma <44740178+jamesma100@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:42:44 -0700 Subject: [PATCH 1/2] minor fixes to concurrency page If the user has been following along with a Scala REPL, `eventualInt` will have already been completed, and thus will return a result. Calling the function again and wrapping it in a Future will deterministically produce the intended result of an uncompleted Future. --- _overviews/scala3-book/concurrency.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_overviews/scala3-book/concurrency.md b/_overviews/scala3-book/concurrency.md index 173e0ff72a..a56e18cb41 100644 --- a/_overviews/scala3-book/concurrency.md +++ b/_overviews/scala3-book/concurrency.md @@ -117,10 +117,10 @@ Therefore, when you work with the result of a future, you use the usual `Try`-ha ### Using `map` with futures `Future` has a `map` method, which you use just like the `map` method on collections. -This is what the result looks like when you call `map` right after creating the variable `f`: +This is what the result looks like when you call `map` right after creating the variable `a`: ```scala -scala> val a = eventualInt.map(_ * 2) +scala> val a = Future(longRunningAlgorithm()).map(_ * 2) a: scala.concurrent.Future[Int] = Future() ``` From 9345ecc5fddafc19356159d067382ab23b14c997 Mon Sep 17 00:00:00 2001 From: James Ma <44740178+jamesma100@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:49:20 -0700 Subject: [PATCH 2/2] same fix for callback section --- _overviews/scala3-book/concurrency.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_overviews/scala3-book/concurrency.md b/_overviews/scala3-book/concurrency.md index a56e18cb41..6740910c4a 100644 --- a/_overviews/scala3-book/concurrency.md +++ b/_overviews/scala3-book/concurrency.md @@ -141,7 +141,7 @@ In addition to higher-order functions like `map`, you can also use callback meth One commonly used callback method is `onComplete`, which takes a *partial function* in which you handle the `Success` and `Failure` cases: ```scala -eventualInt.onComplete { +Future(longRunningAlgorithm()).onComplete { case Success(value) => println(s"Got the callback, value = $value") case Failure(e) => e.printStackTrace }