Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help: How to wait for the subscribed data to finish processing #1655

Open
yangyongyongyong opened this issue Oct 31, 2022 · 0 comments
Open

Comments

@yangyongyongyong
Copy link

now. i use Thread.sleep to make sure all data is processed. bug its not smark. how should i do?

my code:

package org.apache.spark.sql.catalyst.json.com

import zio.ZIO
import monix.eval._
import monix.execution.Callback
import monix.execution.Scheduler

import scala.concurrent.duration.DurationInt
import monix.reactive._
import monix.execution.Scheduler.Implicits.global

import java.lang.Thread.sleep
import scala.util.Random


object ScalaZIOLearn1 {

    def main(args: Array[String]): Unit = {


        val t: Observable[Task[Int]] = {
            Observable
                .fromIterable[Int](11 to 2200000 toIterable)
                .asyncBoundary(OverflowStrategy.BackPressure(3))
                //                .interval(1.second)
                // common filtering and mapping
                .map {
                    x =>
                        println(s"map1 ${x}")
                        sleep(Random.nextInt(3000))
                        x + 10000
                }
                .asyncBoundary(OverflowStrategy.BackPressure(3))
                .map { x =>
                    println(s"map2 ${x}")
                    sleep(Random.nextInt(3000))
                    x * 10
                }
                .map { x =>
                    Task {
                        //                    println(s"flatmap: ${x}")
                        println(s"map3 ${x} start")
                        sleep(15000)
                        println(s"map3 ${x} end")
                        x
                    }
                }
        }
        t.subscribe()


        sleep(Long.MaxValue)  // ?????????

    }


}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant