scalaz / ioeffect

An effect monad for Scalaz 7.2
Other
55 stars 9 forks source link

Fiber compositions does not return any value #28

Closed politrons closed 6 years ago

politrons commented 6 years ago

Sorry about open here this issue, but to be honest there's no community mature enough in StackOverFlow to help on issues related with this library.

I'm trying to do an example of composition of Fibers, based in the for comprehension that you provide with fibboinachi example

I manage to make it work the fibbonachi, but if you execute this one is not returning anything. most probably it will be something silly so sorry in advance XD!

@Test
  def compositionOfFibersFeature(): Unit = {
    println(s"Before ${Thread.currentThread().getName}")
    def composition: IO[Throwable, String] = for {
      fiber <- createIO("Business logic 1").fork
      fiber1 <- createIO("Business logic 2").fork
      v2 <- fiber1.join
      v1 <- fiber.join
    } yield v1 + v2
    println(s"After: ${Thread.currentThread().getName}")
    unsafePerformIO(composition)
  }

  private def createIO(sentence:String):IO[Throwable,String] = {
    IO.point[Throwable, String](sentence)
      .map(sentence => {
        sentence.concat(s"$sentence ${Thread.currentThread().getName}").toUpperCase()
      }).delay(1 second)
  }
politrons commented 6 years ago

yep it was silly it's working sorry about that!

ktonga commented 6 years ago

@politrons you can also ask in the gitter channel, it's full of smart and helpful people.

https://gitter.im/scalaz/scalaz

politrons commented 6 years ago

Cool thanks!