This is how I would do it:
Completable.timer(5, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
.subscribe(this::getTransactionDetails);
A Completable represents a deferred computation with no value but an indication for completion or exception. The static method call timer()
returns a Completable
that signals completion after the specified time period has elapsed, and the subscribe()
call will mean that the method getTransactionDetails()
will be called on the current object when the timer fires. By supplying a Scheduler
as the last argument to Completable.timer()
you control which thread is used to execute getTransactionDetails()
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…