Last active
December 14, 2018 14:51
-
-
Save nkmdev/6d9ae3ee788704c42837823d8188376f to your computer and use it in GitHub Desktop.
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
import { timer, from } from 'rxjs' | |
import { map, concatMap, filter, take } from 'rxjs/operators' | |
pollUntilTaskFinished(taskId) { | |
timer(0, 500) | |
.pipe(concatMap(() => from(fetch(`/tasks/${taskId}`)) | |
.pipe(map(response => response.json()))) | |
) | |
.pipe(filter(backendData => backendData.processing === false)) | |
.pipe(take(1)) | |
.subscribe(() => pollingFinishedFor(taskId)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment