Created
January 30, 2016 11:22
-
-
Save pchi/d47ee357233e09941a31 to your computer and use it in GitHub Desktop.
polling with rx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* create data STREAM | |
* using RX observable timer which allows a starts with time plus interval vs, | |
* flatMapLatest will always merge the last value from stream, | |
* so we don't create multiple observers which are hanging in limbo | |
* give me the first observable that satisfies our predicate, which then unsubscribes OR | |
* unsubscribe after elapsed time of 1 minute | |
*/ | |
function pollData(dataMart) { | |
return Rx.Observable.timer(2000, 15000) | |
.flatMapLatest(() => _getDMStatus(dataMart)) | |
.first(response => response.data.resultset.length > 0) | |
.takeUntilWithTime(60000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment