zak.taccardi
05/24/2018, 8:18 PMzak.taccardi
05/24/2018, 8:18 PM.computation
is backed by a task poolzak.taccardi
05/24/2018, 8:19 PM.io()
for reading/writing to a database or network callsursus
05/24/2018, 8:19 PMursus
05/24/2018, 8:19 PMursus
05/24/2018, 8:19 PMzak.taccardi
05/24/2018, 8:20 PMursus
05/24/2018, 8:21 PMursus
05/24/2018, 8:21 PMursus
05/24/2018, 8:26 PMSQLiteException: database is locked
ubu
05/24/2018, 9:47 PMObservable.create { emitter ->
val listener = db.addListener(
...
emitter.onNext(data)
// there's no onComplete() event here.
)
}
I need to call db.removeListener()
when this observable is unsubscribed. How would you do that? Thanks.
Full disclosure: it’s about wrapping Firebase Realtime Database callbacks.zak.taccardi
05/24/2018, 9:49 PM/**
* Sets a Cancellable on this emitter; any previous Disposable
* or Cancellation will be unsubscribed/cancelled.
* @param c the cancellable resource, null is allowed
*/
void setCancellable(@Nullable Cancellable c);
ubu
05/24/2018, 9:50 PMubu
05/24/2018, 9:50 PMzak.taccardi
05/24/2018, 9:51 PMzak.taccardi
05/24/2018, 9:51 PMubu
05/24/2018, 9:52 PMsubscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
ref.removeEventListener(listener);
}
}));
zak.taccardi
05/24/2018, 9:54 PM.setDisposable
is what you wantzak.taccardi
05/24/2018, 9:54 PM/**
* Sets a Disposable on this emitter; any previous Disposable
* or Cancellation will be unsubscribed/cancelled.
* @param d the disposable, null is allowed
*/
void setDisposable(@Nullable Disposable d);
zak.taccardi
05/24/2018, 9:55 PMObservable
source is disposedubu
05/24/2018, 9:56 PMThe emitter implementations will dispose/cancel this instance when the downstream cancels the flow or after the event generator logic calls Emitter.onError(Throwable), Emitter.onComplete() or when tryOnError(Throwable) succeeds.
zak.taccardi
05/24/2018, 9:56 PMObservable.create { emitter ->
val listener = // . . emitter.onNext(data)
db.addListener(listener)
emitter.setDisposable { db.removeListener(listener) }
}
ubu
05/24/2018, 9:56 PMzak.taccardi
05/24/2018, 9:57 PMjw
05/25/2018, 1:42 PMjw
05/25/2018, 1:43 PMubu
05/25/2018, 3:53 PMjw
05/25/2018, 3:53 PMursus
05/25/2018, 9:39 PMursus
05/25/2018, 9:44 PM