Created
March 17, 2015 00:04
-
-
Save flazz/4fb917aeaa1651377c3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
c := make(chan int, 10) | |
go task1(c) | |
go task2(c) | |
go task3(c) | |
sum := 0 | |
sum += <-c | |
sum += <-c | |
sum += <-c | |
fmt.Println(sum) | |
} | |
func task1(c chan int) { | |
c <- 1 | |
} | |
func task2(c chan int) { | |
c <- 2 | |
} | |
func task3(c chan int) { | |
c <- 3 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import scala.concurrent.{Await, Future} | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
object Main extends App { | |
def task1: Future[Int] = Future { 1 } | |
def task2: Future[Int] = Future { 2 } | |
def task3: Future[Int] = Future { 3 } | |
val f1 = task1 | |
val f2 = task2 | |
val f3 = task3 | |
val sumF = | |
for { | |
a <- f1 | |
b <- f2 | |
c <- f3 | |
} yield a + b + c | |
val sum = Await.result(sumF, Duration.Inf) | |
println(sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment