Skip to content

Instantly share code, notes, and snippets.

@benjchristensen
Created May 14, 2013 16:04
Show Gist options
  • Save benjchristensen/5577144 to your computer and use it in GitHub Desktop.
Save benjchristensen/5577144 to your computer and use it in GitHub Desktop.
Interfaces of Rx
public interface Observable<T> {
public Subscription subscribe(Observer<T> observer);
}
public interface Observer<T> {
/**
* Notifies the Observer that the {@link Observable} has finished sending push-based notifications.
* <p>
* The {@link Observable} will not call this closure if it calls <code>onError</code>.
*/
public void onCompleted();
/**
* Notifies the Observer that the {@link Observable} has experienced an error condition.
* <p>
* If the {@link Observable} calls this closure, it will not thereafter call <code>onNext</code> or <code>onCompleted</code>.
*
* @param e
*/
public void onError(Exception e);
/**
* Provides the Observer with new data.
* <p>
* The {@link Observable} calls this closure 1 or more times, unless it calls <code>onError</code> in which case this closure may never be called.
* <p>
* The {@link Observable} will not call this closure again after it calls either <code>onCompleted</code> or <code>onError</code>.
*
* @param args
*/
public void onNext(T args);
}
public interface Subscription {
/**
* Stop receiving notifications on the {@link Observer} that was registered when this Subscription was received.
* <p>
* This allows unregistering an {@link Observer} before it has finished receiving all events (ie. before onCompleted is called).
*/
public void unsubscribe();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment