Skip to main content

Replace deprecated kotlinx-coroutines-core methods

org.jetbrains.kotlinx.ReplaceDeprecatedKotlinxCoroutinesCore1Methods

Automatically generated recipes to replace deprecated Kotlin methods based on @Deprecated(replaceWith=ReplaceWith(...)) annotations.

Recipe source

GitHub: kotlin-deprecations-kotlinx-coroutines-core-1.yml, Issue Tracker, Maven Central

info

This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.

This recipe is available under the Apache License Version 2.0.

Definition

  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.channels.ChannelsKt receiveOrNull(kotlinx.coroutines.channels.ReceiveChannel, kotlin.coroutines.Continuation)
    • replacement: receiveCatching().getOrNull()
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.channels.ChannelsKt sendBlocking(kotlinx.coroutines.channels.SendChannel, kotlin.Any)
    • replacement: trySendBlocking(element)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.channels.ReceiveChannel poll()
    • replacement: tryReceive().getOrNull()
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.channels.ReceiveChannel receiveOrNull()
    • replacement: receiveCatching().getOrNull()
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.channels.ReceiveChannel receiveOrNull(kotlin.coroutines.Continuation)
    • replacement: receiveCatching().getOrNull()
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.channels.SendChannel offer(*)
    • replacement: trySend(element).isSuccess
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.channels.SendChannel offer(..)
    • replacement: trySend(element).isSuccess
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt cache(kotlinx.coroutines.flow.Flow)
    • replacement: this.shareIn(scope, Int.MAX_VALUE, started = SharingStared.Lazily)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt combineLatest(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, *)
    • replacement: this.combine(other, transform)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt combineLatest(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, *)
    • replacement: combine(this, other, other2, transform)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt combineLatest(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, *)
    • replacement: combine(this, other, other2, other3, transform)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt combineLatest(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow, *)
    • replacement: combine(this, other, other2, other3, transform)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt compose(kotlinx.coroutines.flow.Flow, kotlin.Function1)
    • replacement: let(transformer)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt concatMap(kotlinx.coroutines.flow.Flow, kotlin.Function1)
    • replacement: flatMapConcat(mapper)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt concatWith(kotlinx.coroutines.flow.Flow, *)
    • replacement: onCompletion { emit(value) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt concatWith(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow)
    • replacement: onCompletion { if (it == null) emitAll(other) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt delayEach(kotlinx.coroutines.flow.Flow, kotlin.Long)
    • replacement: onEach { delay(timeMillis) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt delayFlow(kotlinx.coroutines.flow.Flow, kotlin.Long)
    • replacement: onStart { delay(timeMillis) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt flatMap(kotlinx.coroutines.flow.Flow, *)
    • replacement: flatMapConcat(mapper)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt flatten(kotlinx.coroutines.flow.Flow)
    • replacement: flattenConcat()
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt forEach(kotlinx.coroutines.flow.Flow, *)
    • replacement: collect(action)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt merge(kotlinx.coroutines.flow.Flow)
    • replacement: flattenConcat()
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt onErrorResume(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow)
    • replacement: catch { emitAll(fallback) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt onErrorResumeNext(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow)
    • replacement: catch { emitAll(fallback) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt onErrorReturn(kotlinx.coroutines.flow.Flow, *)
    • replacement: catch { emit(fallback) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt onErrorReturn(kotlinx.coroutines.flow.Flow, *, kotlin.Function1)
    • replacement: catch { e -> if (predicate(e)) emit(fallback) else throw e }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt publish(kotlinx.coroutines.flow.Flow)
    • replacement: this.shareIn(scope, 0)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt publish(kotlinx.coroutines.flow.Flow, kotlin.Int)
    • replacement: this.buffer(bufferSize).shareIn(scope, 0)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt replay(kotlinx.coroutines.flow.Flow)
    • replacement: this.shareIn(scope, Int.MAX_VALUE)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt replay(kotlinx.coroutines.flow.Flow, kotlin.Int)
    • replacement: this.shareIn(scope, bufferSize)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt scanFold(kotlinx.coroutines.flow.Flow, *, *)
    • replacement: scan(initial, operation)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt scanReduce(kotlinx.coroutines.flow.Flow, *)
    • replacement: runningReduce(operation)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt skip(kotlinx.coroutines.flow.Flow, kotlin.Int)
    • replacement: drop(count)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt startWith(kotlinx.coroutines.flow.Flow, *)
    • replacement: onStart { emit(value) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt startWith(kotlinx.coroutines.flow.Flow, kotlinx.coroutines.flow.Flow)
    • replacement: onStart { emitAll(other) }
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.FlowKt switchMap(kotlinx.coroutines.flow.Flow, *)
    • replacement: this.flatMapLatest(transform)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt cancel(java.util.concurrent.CancellationException)
    • replacement: currentCoroutineContext().cancel(cause)
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt cancellable()
    • replacement: this
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt catch(*)
    • replacement: this
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt conflate()
    • replacement: this
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt distinctUntilChanged()
    • replacement: this
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt flowOn(kotlin.coroutines.CoroutineContext)
    • replacement: this
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt retry(kotlin.Long, *)
    • replacement: this
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.flow.LintKt retryWhen(*)
    • replacement: this
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]
  • Replace Kotlin method
    • methodPattern: kotlinx.coroutines.selects.SelectBuilder onTimeout(kotlin.Long, *)
    • replacement: onTimeout
    • imports: [kotlinx.coroutines.selects.onTimeout]
    • classpathFromResources: [kotlinx-coroutines-core-jvm-1]

Usage

This recipe has no required configuration parameters and comes from a rewrite core library. It can be activated directly without adding any dependencies.

  1. Add the following to your build.gradle file:
build.gradle
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}

rewrite {
activeRecipe("org.jetbrains.kotlinx.ReplaceDeprecatedKotlinxCoroutinesCore1Methods")
setExportDatatables(true)
}

repositories {
mavenCentral()
}

  1. Run gradle rewriteRun to run the recipe.

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Source files that had results

org.openrewrite.table.SourcesFileResults

Source files that were modified by the recipe run.

Column NameDescription
Source path before the runThe source path of the file before the run. null when a source file was created during the run.
Source path after the runA recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run.
Parent of the recipe that made changesIn a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all.
Recipe that made changesThe specific recipe that made a change.
Estimated time savingAn estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds.
CycleThe recipe cycle in which the change was made.