hiddentao / fast-levenshtein

Efficient Javascript implementation of Levenshtein algorithm with locale-specific collator support.
MIT License
592 stars 56 forks source link

Refactor the async version #3

Closed hiddentao closed 8 years ago

hiddentao commented 10 years ago

People can just use a webworker if they are running this in a browser so the async version is redundant there. In node.js we don't have native web worker support - in such instances process.nextTick would be better than setTimeout - so perhaps a shim for the latter is needed.

Comments from @geekingfrog:

It's weird to pass an option argument after the callback (https://github.com/hiddentao/fast-levenshtein/blob/master/levenshtein.js#L83)
About the async stuff, maybe spawn a child process if in node, or webworker if available in the browser?
It seems strange to do it asynchronously even though there are no need to wait anywhere.
Also lots of duplicate code between the sync and async version.
hiddentao commented 10 years ago

@geekingfrog commented:

I think the easiest way would be to remove the async version. If someone needs to use the lib for giant inputs, a custom service or a different process will be needed anyway.
And btw, prefer setImmediate to nextTick to avoid starving the event loop (https://stackoverflow.com/questions/15349733/setimmediate-vs-nexttick)
hiddentao commented 8 years ago

Using setImmediate now.