1
0
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:
Allan Wang 2019-01-05 00:34:11 -05:00
parent 5c89202f74
commit 4c32104d29
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
3 changed files with 11 additions and 6 deletions

View File

@ -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?) {

View File

@ -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

View File

@ -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) {