sudsy / node-find-files

A Node Module for finding files by attributes. Originally developed to find files modified since a particular date. Uses an eventemitter model so the results can start streaming back as soon as they are found.
15 stars 7 forks source link

How to cancel an existing filereader? #8

Open PAK90 opened 3 years ago

PAK90 commented 3 years ago

I'm using this library hooked up to a text search field, which calls filereader.startSearch() every time the string changes, so as you type in 'bat', it would start a search for 'b', 'ba', and 'bat'. This results in multiple processes running at once, all but the last of which are out of date, so I was wondering if there's a method to stop any existing searches before starting a new one?

sudsy commented 3 years ago

I'm certainly open to something like that. Perhaps passing in a cancellation token? https://www.npmjs.com/package/cancellationtoken

PAK90 commented 3 years ago

I've not used that library before; how would it work with filereader?

sudsy commented 3 years ago

You would allow a cancellation token to be passed as one of the options. Then in the loop that is searching through the files you would check if the token is cancelled before continuing.