Stay organized with collections
Save and categorize content based on your preferences.
Subscription
interface Subscription
Message control linking a Publisher
and Subscriber
. Subscribers receive items only when requested, and may cancel at any time. The methods in this interface are intended to be invoked only by their Subscribers; usages in other contexts have undefined effects.
Summary
Public methods |
abstract Unit |
Causes the Subscriber to (eventually) stop receiving messages.
|
abstract Unit |
Adds the given number n of items to the current unfulfilled demand for this subscription.
|
Public methods
cancel
abstract fun cancel(): Unit
Causes the Subscriber to (eventually) stop receiving messages. Implementation is best-effort -- additional messages may be received after invoking this method. A cancelled subscription need not ever receive an onComplete
or onError
signal.
request
abstract fun request(n: Long): Unit
Adds the given number n
of items to the current unfulfilled demand for this subscription. If n
is less than or equal to zero, the Subscriber will receive an onError
signal with an IllegalArgumentException
argument. Otherwise, the Subscriber will receive up to n
additional onNext
invocations (or fewer if terminated).
Parameters |
n |
Long: the increment of demand; a value of Long.MAX_VALUE may be considered as effectively unbounded |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Flow.Subscription\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nSubscription\n============\n\n```\ninterface Subscription\n```\n\n|---------------------------------------------|\n| [java.util.concurrent.Flow.Subscription](#) |\n\nMessage control linking a [Publisher](/reference/kotlin/java/util/concurrent/Flow.Publisher) and [Subscriber](/reference/kotlin/java/util/concurrent/Flow.Subscriber). Subscribers receive items only when requested, and may cancel at any time. The methods in this interface are intended to be invoked only by their Subscribers; usages in other contexts have undefined effects.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [cancel](#cancel())`()` Causes the Subscriber to (eventually) stop receiving messages. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [request](#request(kotlin.Long))`(`n:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Adds the given number `n` of items to the current unfulfilled demand for this subscription. |\n\nPublic methods\n--------------\n\n### cancel\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun cancel(): Unit\n```\n\nCauses the Subscriber to (eventually) stop receiving messages. Implementation is best-effort -- additional messages may be received after invoking this method. A cancelled subscription need not ever receive an `onComplete` or `onError` signal. \n\n### request\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun request(n: Long): Unit\n```\n\nAdds the given number `n` of items to the current unfulfilled demand for this subscription. If `n` is less than or equal to zero, the Subscriber will receive an `onError` signal with an [IllegalArgumentException](../../lang/IllegalArgumentException.html#) argument. Otherwise, the Subscriber will receive up to `n` additional `onNext` invocations (or fewer if terminated).\n\n| Parameters ||\n|-----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `n` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): the increment of demand; a value of `Long.MAX_VALUE` may be considered as effectively unbounded |"]]