use of io.reactivex.functions.Consumer in project RxDownload by ssseasonnn.
the class DownloadService method startDispatch.
/**
* start dispatch download queue.
*/
private void startDispatch() {
disposable = Observable.create(new ObservableOnSubscribe<DownloadMission>() {
@Override
public void subscribe(ObservableEmitter<DownloadMission> emitter) throws Exception {
DownloadMission mission;
while (!emitter.isDisposed()) {
try {
log(WAITING_FOR_MISSION_COME);
mission = downloadQueue.take();
log(Constant.MISSION_COMING);
} catch (InterruptedException e) {
log("Interrupt blocking queue.");
continue;
}
emitter.onNext(mission);
}
emitter.onComplete();
}
}).subscribeOn(Schedulers.newThread()).subscribe(new Consumer<DownloadMission>() {
@Override
public void accept(DownloadMission mission) throws Exception {
mission.start(semaphore);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
log(throwable);
}
});
}
use of io.reactivex.functions.Consumer in project RxFacebook by YouClap.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
callbackManager = CallbackManager.Factory.create();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
List<String> perm = new ArrayList<>();
perm.add("email");
perm.add("public_profile");
RxFacebookLogin.logInWithReadPermissions(perm).subscribe(new Consumer<LoginResult>() {
@Override
public void accept(@NonNull LoginResult loginResult) throws Exception {
Log.d(LOG_TAG, "accept " + loginResult.getAccessToken());
}
}, new Consumer<Throwable>() {
@Override
public void accept(@NonNull Throwable throwable) throws Exception {
Log.e(LOG_TAG, "error ", throwable);
}
}, new Action() {
@Override
public void run() throws Exception {
Log.e(LOG_TAG, "onCompleted");
}
});
}
});
}
Aggregations