Skip to content

Instantly share code, notes, and snippets.

@nkmdev
Last active December 14, 2018 14:51
Show Gist options
  • Save nkmdev/6d9ae3ee788704c42837823d8188376f to your computer and use it in GitHub Desktop.
Save nkmdev/6d9ae3ee788704c42837823d8188376f to your computer and use it in GitHub Desktop.
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