|
1 | 1 | ## Scala Concurrent Learn |
2 | 2 | Learn about scala futures and promises, concurrent programming |
| 3 | + |
| 4 | +#### Scala Future Basics |
| 5 | + |
| 6 | +Learn about Futures and how to print its results, Feature is used for read. [example code](src/main/scala/FuturesAndPromises/ScalaFuture.scala) |
| 7 | + |
| 8 | +#### Scala Promise |
| 9 | + |
| 10 | +Promise can be written (normally only once), Promise is used for write. |
| 11 | +[example code](src/main/scala/FuturesAndPromises/ScalaPromise.scala) |
| 12 | + |
| 13 | +#### Scala Concurrent example |
| 14 | + |
| 15 | +How to do calculation concurrently with Features. [example code](src/main/scala/FuturesAndPromises/ExampleConcurrent.scala) |
| 16 | + |
| 17 | +#### Scala Synchronous example |
| 18 | + |
| 19 | +How to do calculation synchronously with Features, used Await.result to wait result. [example code](src/main/scala/FuturesAndPromises/ExampleSynchronous.scala) |
| 20 | + |
| 21 | +#### Scala Parallel calculation example |
| 22 | + |
| 23 | +How to do calculation parallel with Features, used Future.sequence. |
| 24 | +[example code](src/main/scala/FuturesAndPromises/ExampleParallel.scala) |
| 25 | + |
| 26 | +#### Scala Parallel-2 calculation example |
| 27 | + |
| 28 | +How to do calculation parallel with Features, used Future.traverse, traverse and sequence are similar, difference is that traverse |
| 29 | +easily convert all the Option[Int] into just Int type. |
| 30 | +[example code](src/main/scala/FuturesAndPromises/ExampleParallel2.scala) |
| 31 | + |
| 32 | +#### Scala Zip two features example |
| 33 | + |
| 34 | +The Future.zip will create a new future, whose return type will be a tuple holding the return types of the two futures. |
| 35 | +[example code-1](src/main/scala/FuturesAndPromises/ExampleFutureZip.scala), [example dode-2](src/main/scala/FuturesAndPromises/ExampleReadingFile.scala) |
| 36 | + |
| 37 | +#### Scala FoldLeft example |
| 38 | + |
| 39 | +The foldLeft on your future operations will be run asynchronously from left to right. |
| 40 | +[example code](src/main/scala/FuturesAndPromises/ExampleFoldLeft.scala) |
| 41 | + |
| 42 | +#### Scala ReduceLeft example |
| 43 | + |
| 44 | +The reduceLeft is similar with foldLeft, however, reduceLeft() does not allow you to provide a default value. |
| 45 | +[example code](src/main/scala/FuturesAndPromises/ExampleReduceLeft.scala) |
| 46 | + |
| 47 | +#### Scala FutureThen example |
| 48 | + |
| 49 | +The andThen is used for passing partialFunction. |
| 50 | +[example code](src/main/scala/FuturesAndPromises/ExampleFutureThen.scala) |
| 51 | + |
| 52 | +#### Scala FirstCompletedOf callback function example |
| 53 | + |
| 54 | +The firstCompletedOf return any one of the futures which finish first. |
| 55 | +[example code](src/main/scala/FuturesAndPromises/ExampleFirstCompletedOf.scala) |
| 56 | + |
| 57 | +#### Scala ExecutionContext example |
| 58 | + |
| 59 | +In this example, learn how to create single threaded executionContext. |
| 60 | +[example code](src/main/scala/FuturesAndPromises/ExampleExecutionContext.scala) |
| 61 | + |
| 62 | +#### Scala Future recover example |
| 63 | + |
| 64 | +The recover function recovers error message. |
| 65 | +[example code](src/main/scala/FuturesAndPromises/ExampleFutureRecover.scala) |
| 66 | + |
| 67 | +#### More resources for concurrent and parallel programming in Scala |
| 68 | +- [Scala Futures for Beginners](http://allaboutscala.com/tutorials/chapter-9-beginner-tutorial-using-scala-futures/#futures-introduction) |
| 69 | +- [Monix](https://monix.io/) |
| 70 | +- [Akka Actors](https://doc.akka.io/docs/akka/current/typed/actors.html#:~:text=SayHello(%22Akka%22))%3B,running%20many%20actors%2C%20per%20JVM.) |
0 commit comments