How do you combine multiple Scalaz threads so that the completion order is preserved, but striping is not applied?

var num =0
var num2 = 3333
val p2 = Process.eval {
  Thread.sleep(10000)
  Task.delay {
    Thread.sleep(10000)
    num2 = num2 + 1
    s"hi ${num2}"
  }
}.repeat.take(15)

//p2: scalaz.stream.Process[[x]scalaz.concurrent.Task[x],String] =
// Await(scalaz.concurrent.Task@5a554f1c,
//<function1>,Halt(scalaz.stream.Process$End$),Halt(scalaz.stream.Process$End$))

val p1 = Process.eval {
  Thread.sleep(2000)
  Task.delay { 
    Thread.sleep(2000)
    num = num + 1
    s"hi $num"
  }
}.repeat.take(15)

//p1: scalaz.stream.Process[[x]scalaz.concurrent.Task[x],String] = 
// Await(scalaz.concurrent.Task@7a54e904,
// <function1>,Halt(scalaz.stream.Process$End$),Halt(scalaz.stream.Process$End$))

// this interleaves them and I get disjunctions showing me their order
(p1 either p2).map(println).run.run

// this gives me the strings that are interleaved
(p1 interleave p2).map(println).run.run

How do you get a process that is a combination of two Processes, but only in the order in which they arrive (which means that if the left goes twice in front of the right, this is normal, give the left twice, and then when its radiation comes to the right later) ?

I am looking for a shorter sleep to occur more often, and see how it comes out several times to a slower process. Thank you in advance for having time to read this, and especially those who can share some understanding.

+3
source share
1 answer

Eric

scalaz Process.wye, , wye. , , /, , , . , , , .

, - , , p1 .

:

val p1 = Process(1,2,3).toSource
val p2 = Process(10) fby Process.sleep(1 second) fby Process(20,30).toSource

(p1 either p2).runLog.run.foreach(println)

-\/(1)
\/-(10)
-\/(2)
-\/(3)
\/-(20)
\/-(30)
+4

All Articles