Stay organized with collections
Save and categorize content based on your preferences.
Flow.Subscription
public
static
interface
Flow.Subscription
java.util.concurrent.Flow.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
void
|
cancel()
Causes the Subscriber to (eventually) stop receiving
messages.
|
abstract
void
|
request(long n)
Adds the given number n of items to the current
unfulfilled demand for this subscription.
|
Public methods
cancel
public abstract void cancel ()
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
public abstract void request (long n)
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](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nFlow.Subscription\n=================\n\n\n`\npublic\nstatic\n\n\ninterface\nFlow.Subscription\n`\n\n\n`\n\n\n`\n\n|----------------------------------------|\n| java.util.concurrent.Flow.Subscription |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nMessage control linking a [Publisher](/reference/java/util/concurrent/Flow.Publisher) and [Subscriber](/reference/java/util/concurrent/Flow.Subscriber). Subscribers receive items only when requested,\nand may cancel at any time. The methods in this interface are\nintended to be invoked only by their Subscribers; usages in\nother contexts have undefined effects.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[cancel](/reference/java/util/concurrent/Flow.Subscription#cancel())`() ` Causes the Subscriber to (eventually) stop receiving messages. |\n| ` abstract void` | ` `[request](/reference/java/util/concurrent/Flow.Subscription#request(long))`(long n) ` 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](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void cancel ()\n```\n\nCauses the Subscriber to (eventually) stop receiving\nmessages. Implementation is best-effort -- additional\nmessages may be received after invoking this method.\nA cancelled subscription need not ever receive an\n`onComplete` or `onError` signal.\n\n\u003cbr /\u003e\n\n### request\n\nAdded in [API level 30](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void request (long n)\n```\n\nAdds the given number `n` of items to the current\nunfulfilled demand for this subscription. If `n` is\nless than or equal to zero, the Subscriber will receive an\n`onError` signal with an [IllegalArgumentException](/reference/java/lang/IllegalArgumentException) argument. Otherwise, the\nSubscriber will receive up to `n` additional `onNext` invocations (or fewer if terminated).\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|----------------------------------------------------------------------------------------------------------------|\n| `n` | `long`: the increment of demand; a value of `Long.MAX_VALUE` may be considered as effectively unbounded \u003cbr /\u003e |"]]