How can I abort a javascript function if a second call to it is made?
<p>Google has failed me (which probably means it can't be done).</p>

<p>Is there a way to kill a Javascript function if it's still running when it gets called again?</p>

<p>Situation is this. I have an HTML5 Android app which has a search function. As the user types, it searches the HTML5 database for matches. Each keystroke in the search box fires off a function to get suggestions. But because the user can type faster than the database engine can return suggestions on relatively slow devices (like my own, or indeed the emulator) subsequent keypresses get queued up, so that it can take a while for the suggestions to match what the user's typed.</p>

<p>So what I'd like to do is to find some way of killing off a previous invocation of the getSuggestions function if it's invoked again before finishing.</p>

<p>Easy enough to set a global which the function tests at various stages and aborts if it sees it, but that won't stop queries piling up in the database engine, which I'm guessing is probably where the blockage is occurring. Which is why I'm looking for some way to kill off the whole function.</p>

<p>Any suggestions gratefully received. Thanks.</p>
