January 2019
Intermediate to advanced
392 pages
10h 11m
English
The fromArray function is one of many static factory methods that are provided by the Flux class. If we want to create our own source of events, we can use the from function. Let's create an instance of the Flux class that emits the Unit object when a user clicks on the button.
We can implement this case as follows:
Flux.from<Unit> { subscriber -> findViewById<Button>(R.id.button).setOnClickListener { subscriber.onNext(Unit) }}.subscribe { Toast.makeText(this, "Clicked!", Toast.LENGTH_LONG).show()}
The preceding snippet shows how to wrap an Observer into an instance of the Flux class. This example illustrates using the from function to create a new instance of the Flux class.
Let's run an application and press the ...
Read now
Unlock full access