scalaz - fs2 Task.start vs async -


i have 2 tasks:

  val t = system.currenttimemillis()    def first: fs2.task[int] = fs2.task.fromfuture(future.successful {     println(s"${ system.currenttimemillis() - t} - first")     thread.sleep(100)     1   })    def second: fs2.task[int] = fs2.task.fromfuture(future.successful {     println(s"${system.currenttimemillis() - t} - second")     thread.sleep(200)     2   }) 

i want start them in parallel, , run function on results in end (pretty i'd vs applicative map2). works fine:

  val comb = {     ta ← fs2.task.start(first)     tb ← fs2.task.start(second)     ← ta     b ← tb   } yield {     println("complete")     + b   }  comb.unsaferun()  

output: 164 - first 164 - second

it bit tedious write line in comprehension every time. suprise neither

import fs2.interop.scalaz._ import scalaz.syntax.applicative._ val comb2 = (first |@| second) {_ + _} 

output: 197 - first 318 - second

nor

  val comb1 = {     ← first.async     b ← second.async   } yield {     + b   } 

output: 202 - first 323 - second

worked. while in first case tasks started simultaneuosly, in latter 2, began 1 after another.

what missing? reading implementation of async understood, intent make first snippet syntactically attractive, cant believe there bug, possibly misuse async?


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

android - Unable to generate FCM token from dynamically instantiated Firebase -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -