![]() ![]() ![]() Let's begin by defining our already familiar donutStock() method which returns a Future of type Int. #SCALA FUTURE HOW TO#We've in fact already shown in chain futures using flatMap and chain futures using for comprehension how to use the flatMap() function or the syntactic sugar of the for comprehension to sequence futures. In this section, we will provide some additional details on the idea of composing futures.ġ. Define a method which returns a Future Option Step 2: Access value returned by future using map() method However brevity is a blunt tool that can also deliver the opposite effect: After correctness, think always of the reader. Less typing is less reading, and less reading is often faster reading, and thus brevity enhances clarity. You should see the following output when you run your Scala application in IntelliJ: Scala provides many tools that enable succinct expression. Import .globalĭef donutStock(donut: String): Future = Future vanilla donuts")) Println("Step 1: Define a method which returns a Future") Note however that instead of returning an Int type, we are returning a Future of type Int, i.e., Future. The method donutStock() will return an Int to represent the number of donuts we have in stock for a given type of donut. The method below builds on the concepts we've learned from Chapter 3 and shows how to create a method which is intended to run asynchronously. In Chapter 3 A Beginner's Tutorial To Using Function in Scala, we showed how to define and use methods and functions in Scala. #SCALA FUTURE CODE#This tutorial is an extension to the official Scala documentation on Scala Futures. We will provide short code snippets to help you get familiar with using Scala Futures to easily write asynchronous non-blocking operations.ġ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |