001/*************************************************** 002 * Licensed under MIT No Attribution (SPDX: MIT-0) * 003 ***************************************************/ 004 005package org.reactivestreams; 006 007/** 008 * Will receive call to {@link #onSubscribe(Subscription)} once after passing an instance of {@link Subscriber} to {@link Publisher#subscribe(Subscriber)}. 009 * <p> 010 * No further notifications will be received until {@link Subscription#request(long)} is called. 011 * <p> 012 * After signaling demand: 013 * <ul> 014 * <li>One or more invocations of {@link #onNext(Object)} up to the maximum number defined by {@link Subscription#request(long)}</li> 015 * <li>Single invocation of {@link #onError(Throwable)} or {@link Subscriber#onComplete()} which signals a terminal state after which no further events will be sent. 016 * </ul> 017 * <p> 018 * Demand can be signaled via {@link Subscription#request(long)} whenever the {@link Subscriber} instance is capable of handling more. 019 * 020 * @param <T> the type of element signaled 021 */ 022public interface Subscriber<T> { 023 024 /** 025 * Invoked after calling {@link Publisher#subscribe(Subscriber)}. 026 * <p> 027 * No data will start flowing until {@link Subscription#request(long)} is invoked. 028 * <p> 029 * It is the responsibility of this {@link Subscriber} instance to call {@link Subscription#request(long)} whenever more data is wanted. 030 * <p> 031 * The {@link Publisher} will send notifications only in response to {@link Subscription#request(long)}. 032 * 033 * @param s the {@link Subscription} that allows requesting data via {@link Subscription#request(long)} 034 */ 035 public void onSubscribe(Subscription s); 036 037 /** 038 * Data notification sent by the {@link Publisher} in response to requests to {@link Subscription#request(long)}. 039 * 040 * @param t the element signaled 041 */ 042 public void onNext(T t); 043 044 /** 045 * Failed terminal state. 046 * <p> 047 * No further events will be sent even if {@link Subscription#request(long)} is invoked again. 048 * 049 * @param t the throwable signaled 050 */ 051 public void onError(Throwable t); 052 053 /** 054 * Successful terminal state. 055 * <p> 056 * No further events will be sent even if {@link Subscription#request(long)} is invoked again. 057 */ 058 public void onComplete(); 059}