Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes no functional changes. However, it does drop support for Node 0.x.
I have refactored the code using
co
to better control the flow of asynchronous code.My primary motivation for using
co
is to improve error handling. In callback-style asynchronous code, it's really easy to swallow exceptions. For example:Neither of the errors above are passed to
callback
, which means that whoever is callinginfo
cannot catch them.You can wrap everything in
try/catch
blocks, but this starts to get really messy for deep-nested code.I looked at using
async
, which has the advantage of supporting Node 0.x, and it's already a dependency. However, it comes with some of the same problems, and some new ones.Consider:
co
, on the other hand, treats async and sync errors the same, so you don't need to worry about uncaught exceptions. It also allows you to keep everything in the same scope, making reasoning about your code much easier.The syntax is very similar to the proposed
async
/await
syntaxAs I noted in pull request #10, I'm trying to debug timeouts in my tile server, and I'm suspecting that some of the timeouts are caused by uncaught exceptions in upstream code (including tilelive-tmstyle). I'm hoping these changes will allow me to catch, log, and fix some of these errors.