Skip to content

Instantly share code, notes, and snippets.

@zachad
zachad / vanilla-ajax-poll.js
Created April 16, 2018 15:40 — forked from twmbx/vanilla-ajax-poll.js
Polling in JS with an async ajax call that returns a promise ( modified from: https://davidwalsh.name/javascript-polling )
// The polling function
function poll(fn, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
var checkCondition = function(resolve, reject) {
var ajax = fn();
// dive into the ajax promise
ajax.then( function(response){
// If the condition is met, we're done!
# big_array has over 120,000 strings in it
def select_search(q)
big_array.select do |s|
s =~ /^#{Regexp.esecap(q)}/
end
end
def grep_search(q)
big_array.grep( /^#{Regexp.escape(q)}/ )