Skip to content

Commit

Permalink
Deprecate asWorker() extension on deferreds and channels.
Browse files Browse the repository at this point in the history
The reasons for deprecating Deferred.asWorker() is documented in #10.
`BroadcastChannel` is being entirely replaced by `SharedFlow`/`StateFlow`,
which are covered by the `Flow.asWorker()` extension.
  • Loading branch information
zach-klippenstein committed Jun 17, 2020
1 parent f4f4786 commit 0114c79
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion workflow-core/src/main/java/com/squareup/workflow/Worker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ interface Worker<out OutputT> {
*/
@OptIn(FlowPreview::class)
inline fun <reified OutputT> from(noinline block: suspend () -> OutputT): Worker<OutputT> =
block.asFlow().asWorker()
block.asFlow()
.asWorker()

/**
* Creates a [Worker] from a function that returns a single value.
Expand Down Expand Up @@ -285,6 +286,13 @@ inline fun <reified OutputT> Flow<OutputT>.asWorker(): Worker<OutputT> =
* Worker.from { doThing().await() }
* ```
*/
@Deprecated(
"Use Worker.from { await() }",
ReplaceWith(
"Worker.from { this.await() }",
"com.squareup.workflow.Worker"
)
)
inline fun <reified OutputT> Deferred<OutputT>.asWorker(): Worker<OutputT> =
from { await() }

Expand All @@ -295,6 +303,8 @@ inline fun <reified OutputT> Deferred<OutputT>.asWorker(): Worker<OutputT> =
FlowPreview::class,
ExperimentalCoroutinesApi::class
)
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use SharedFlow or StateFlow with Flow.asWorker()")
inline fun <reified OutputT> BroadcastChannel<OutputT>.asWorker(): Worker<OutputT> =
asFlow().asWorker()

Expand All @@ -314,6 +324,7 @@ inline fun <reified OutputT> BroadcastChannel<OutputT>.asWorker(): Worker<Output
* True by default.
*/
@OptIn(ExperimentalCoroutinesApi::class)
@Deprecated("Use consumeAsFlow() or receiveAsFlow() with Flow.asWorker().")
inline fun <reified OutputT> ReceiveChannel<OutputT>.asWorker(
closeOnCancel: Boolean = true
): Worker<OutputT> = create {
Expand Down

0 comments on commit 0114c79

Please sign in to comment.