Skip to content

Commit

Permalink
Add RibCoroutineWorker.bind receiving multiple workers
Browse files Browse the repository at this point in the history
  • Loading branch information
FranAguilera committed Aug 10, 2023
1 parent 484a476 commit d719af0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package com.uber.rib.workers.root.main.ribworkerselection
enum class RibWorkerBindTypeClickType {
SINGLE_WORKER_BIND_CALLER_THREAD,
SINGLE_WORKER_BIND_BACKGROUND_THREAD,
BIND_MULTIPLE_WORKERS,
BIND_MULTIPLE_DEPRECATED_WORKERS,
BIND_MULTIPLE_RIB_COROUTINE_WORKERS,
BIND_RIB_COROUTINE_WORKER,
WORKER_TO_RIB_COROUTINE_WORKER,
RIB_COROUTINE_WORKER_TO_WORKER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ class RibWorkerSelectionInteractor(
updateViewModel(ioWorker::class.simpleName)
WorkerBinder.bind(this, ioWorker)
}
RibWorkerBindTypeClickType.BIND_MULTIPLE_WORKERS -> {
RibWorkerBindTypeClickType.BIND_MULTIPLE_DEPRECATED_WORKERS -> {
val workers = listOf(backgroundWorker, defaultWorker, ioWorker, uiWorker)
updateViewModel("Multiple workers ")
updateViewModel("Multiple deprecated workers ")
WorkerBinder.bind(this, workers)
}
RibWorkerBindTypeClickType.BIND_MULTIPLE_RIB_COROUTINE_WORKERS -> {
val workers = listOf(defaultRibCoroutineWorker, defaultRibCoroutineWorker)
updateViewModel("Multiple RibCoroutineWorkers ")
coroutineScope.bind(workers)
}
RibWorkerBindTypeClickType.BIND_RIB_COROUTINE_WORKER -> {
updateViewModel(defaultRibCoroutineWorker::class.simpleName)
coroutineScope.bind(defaultRibCoroutineWorker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ fun RibWorkerSelectionView(

AddButton(
eventStream,
RibWorkerBindTypeClickType.BIND_MULTIPLE_WORKERS,
"Bind multiple workers",
RibWorkerBindTypeClickType.BIND_MULTIPLE_DEPRECATED_WORKERS,
"Bind multiple Deprecated Workers",
)

AddButton(
eventStream,
RibWorkerBindTypeClickType.BIND_MULTIPLE_RIB_COROUTINE_WORKERS,
"Bind multiple RibCoroutineWorkers",
)

AddButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public fun CoroutineScope.bind(
return BindWorkerHandleImpl(bindJob, unbindJob)
}

/** Binds a list of [worker]'s in a scope that is a child of the [CoroutineScope] receiver. */
@JvmOverloads
public fun CoroutineScope.bind(
workers: Iterable<RibCoroutineWorker>,
coroutineContext: CoroutineContext = RibDispatchers.Default,
) {
for (worker in workers) {
bind(worker, coroutineContext)
}
}

/**
* Guarantees to run synchronous [init] block exactly once in an undispatched manner.
*
Expand Down

0 comments on commit d719af0

Please sign in to comment.