Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronous reads #82

Open
eliasmalik opened this issue Nov 14, 2016 · 3 comments
Open

Synchronous reads #82

eliasmalik opened this issue Nov 14, 2016 · 3 comments
Assignees

Comments

@eliasmalik
Copy link

Here: https://github.com/fac-u/autocompleter/blob/master/src/autocomplete.js#L7

Synchronous reads are blocking and will stop your server from responding to subsequent requests while it completes. Not a big deal here, but in a real project it can be a problem. It's best to avoid synchronous operations if possible.

You are also reading the orderedDict.json every time you call the autocomplete function. This is quite inefficient.

A better solution which would avoid having to change the API of your autocomplete function to be asynchronous would be to read the orderedDict.json into memory when the server starts. Then your function would simply reference an in-memory object (relatively fast) instead of reading a file (relatively slow).

@stevehopkinson
Copy link
Contributor

Nice one. We'll have a look into this after the code review.

@SavageWilliam
Copy link
Contributor

"inspired by NodeGroup2"

function startServer() {
  dictionaryFile.readDictionary(null,null, function() {
  server.listen(port, function(){
    console.log("Dictionary loaded, server listening to port " + port + ", ready to accept requests");
  });
})
}

startServer();

@eliasmalik
Copy link
Author

eliasmalik commented Nov 14, 2016

@SavageWilliam see NodeGroup2/autocomplete-project#74 for my comments on that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants