Skip to content

Instantly share code, notes, and snippets.

View kalpeshhpatel's full-sized avatar

Kalpesh Patel kalpeshhpatel

View GitHub Profile
@kalpeshhpatel
kalpeshhpatel / rx-shortpoll.js
Created May 21, 2018 10:23 — forked from pchi/rx-shortpoll.js
Short polling until predicate is met with RXJS
function getWikipediaSearchResults(term) {
return Rx.Observable.create(function forEach(observer) {
var cancelled = false;
var url = 'http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search='
+ encodeURIComponent(term) + '&callback=?';
$.getJSON(url, function(data) {
if (!cancelled) {
observer.onNext(data[1]);
observer.onCompleted();
}