Files

README.md

auto-abort

Only keep a single instance, aborting previous instances on subsequent calls

Install

npm install auto-abort

Usage

varautoAbort=require('auto-abort')varautoXhr=autoAbort(require('xhr'))autoXhr({url: '/autocomplete',json: {q: 'hel'}},handleResponse)autoXhr({url: '/autocomplete',json: {q: 'hell'}},handleResponse)autoXhr({url: '/autocomplete',json: {q: 'hello'}},handleResponse)functionhandleResponse(err,data,res){// Should only be called once, with the most recent request}

API

autoAbort(fn, [abortHandler])

Wraps fn with a function that will only keep a single instance of whatever fn
returns around, calling .abort() on the previous instance before calling
fn again. If you need to call another function than .abort(), use the
abortHandler.