DefinitelyTyped/types/rsocket-types/ReactiveStreamTypes.d.ts
Adrian Hope-Bailie 8727a4fa0a Add rsocket types (#36076)
* Add rsocket types

* Drop `types` from `tsconfig.json

Use triple-slash references

* Fix linting errors

* Remove private members

* Fix linting errors
2019-06-20 14:05:22 -07:00

43 lines
1.2 KiB
TypeScript

/**
* Core types per the [ReactiveStreams specification](http://www.reactive-streams.org/)
*/
/**
* Represents an asynchronous, pull-based stream of values. Calling
* `subscribe()` causes the subscriber's `onSubscribe()` method to be be invoked
* with a Subscription object that has two methods:
* - `cancel()`: stops the publisher from publishing any more values.
* - `request(n)`: requests `n` additional values.
*
* The subscriber can use `request(n)` to pull additional values from the
* stream.
*/
export interface IPublisher<T> {
subscribe: (subscriber?: Partial<ISubscriber<T>>) => void;
map: <R>(fn: (data: T) => R) => IPublisher<R>;
}
/**
* An underlying source of values for a Publisher.
*/
export interface ISubscription {
cancel: () => void;
request: (n: number) => void;
}
/**
* A handler for values provided by a Publisher.
*/
export interface ISubscriber<T> {
onComplete: () => void;
onError: (error: Error) => void;
onNext: (value: T) => void;
onSubscribe: (subscription: ISubscription) => void;
}
/**
* Similar to Subscriber, but without onSubscribe.
*/
export interface ISubject<T> {
onComplete: () => void;
onError: (error: Error) => void;
onNext: (value: T) => void;
}