mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-09-19 23:21:34 +02:00
Use conflated channels where possible, resolves #1314
This commit is contained in:
parent
5c89202f74
commit
4c32104d29
@ -34,7 +34,7 @@ import org.jsoup.Jsoup
|
||||
class MainActivity : BaseMainActivity() {
|
||||
|
||||
override val fragmentChannel = BroadcastChannel<Int>(10)
|
||||
override val headerBadgeChannel = Channel<String>(Channel.RENDEZVOUS)
|
||||
override val headerBadgeChannel = Channel<String>(Channel.CONFLATED)
|
||||
var lastPosition = -1
|
||||
|
||||
override fun onNestedCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -43,6 +43,7 @@ import com.pitchedapps.frost.utils.Prefs
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
|
||||
import kotlinx.coroutines.channels.ReceiveChannel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ -82,9 +83,13 @@ abstract class FrostContentView<out T> @JvmOverloads constructor(
|
||||
override val core: FrostContentCore
|
||||
get() = coreView
|
||||
|
||||
override val refreshChannel: BroadcastChannel<Boolean> = BroadcastChannel(100)
|
||||
override val progressChannel: BroadcastChannel<Int> = BroadcastChannel(100)
|
||||
override val titleChannel: BroadcastChannel<String> = BroadcastChannel(100)
|
||||
/**
|
||||
* While this can be conflated, there exist situations where we wish to watch refresh cycles.
|
||||
* Here, we'd need to make sure we don't skip events
|
||||
*/
|
||||
override val refreshChannel: BroadcastChannel<Boolean> = BroadcastChannel(10)
|
||||
override val progressChannel: BroadcastChannel<Int> = ConflatedBroadcastChannel()
|
||||
override val titleChannel: BroadcastChannel<String> = ConflatedBroadcastChannel()
|
||||
|
||||
override lateinit var scope: CoroutineScope
|
||||
|
||||
|
@ -150,12 +150,12 @@ class CoroutineTest {
|
||||
|
||||
/**
|
||||
* Not a true throttle, but for things like fetching header badges, we want to avoid simultaneous fetches.
|
||||
* As a result, I want to test that the usage of offer along with a rendezvous channel will work as I expect.
|
||||
* As a result, I want to test that the usage of offer along with a conflated channel will work as I expect.
|
||||
* Events should be consumed when there is no pending consumer on previous elements.
|
||||
*/
|
||||
@Test
|
||||
fun throttledChannel() {
|
||||
val channel = Channel<Int>(Channel.RENDEZVOUS)
|
||||
val channel = Channel<Int>(Channel.CONFLATED)
|
||||
runBlocking {
|
||||
val deferred = async {
|
||||
listen(channel) {
|
||||
|
Loading…
Reference in New Issue
Block a user