Skip to content

Commit

Permalink
Review: add log about why wrap asyncronous function with keyword async
Browse files Browse the repository at this point in the history
  • Loading branch information
lvancraen committed Jun 21, 2019
1 parent e233490 commit 9dc268d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions helpers/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ function exportTable(tableName, gtfs, outputPath, callback) {

let rows = [];

/*
About why the async wrapper is used inside the async.eachSeries:
If the function async.eachSeries runs without doing anything, just calling the callback (which
happens when there are a lot of empty objects), it crashes. It is a known bug of async.
They don't fix it due to performance reasons (see Common Pitfalls - https://caolan.github.io/async/v3/)
To deal with this, we simply wrap the possible asynchronous function with the keyword async.
The ES2017 async functions are returned as-is.
This is useful for preventing stack overflows (RangeError: Maximum call stack size exceeded),
and generally keeping Zalgo contained. Hence, Async Functions are immune to Zalgo's corrupting influences,
as they always resolve on a later tick.
More info on Zalgo (https://blog.izs.me/2013/08/designing-apis-for-asynchrony)
*/
async.eachSeries(gtfs.getIndexedTable(tableName), async ([key, object]) => {
if (deepness === 0 || deepness === 1) {
if (gtfs._preExportItemFunction) {
Expand Down

0 comments on commit 9dc268d

Please sign in to comment.