Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[node] Don't call callbacks synchronously #8243

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions platform/node/test/memory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ test('Memory', function(t) {

var options = {
request: function(req, callback) {
if (req.url == null) {
t.fail('invalid file request');
} else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('json')) {
callback(null, { data: sprite_json });
} else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('png')) {
callback(null, { data: sprite_png });
} else if (req.url.indexOf('fonts') > -1 && req.url.endsWith('pbf')) {
callback(null, { data: glyph });
} else if (req.url.endsWith('mapbox.satellite')) {
callback(null, { data: source_raster });
} else if (req.url.indexOf('satellite') > -1 && (req.url.endsWith('png') || req.url.endsWith('webp'))) {
callback(null, { data: tile_raster });
} else if (req.url.endsWith('mapbox.mapbox-streets-v7')) {
callback(null, { data: source_vector });
} else if (req.url.indexOf('streets') > -1 && req.url.endsWith('pbf')) {
callback(null, { data: tile_vector });
} else {
t.fail('unhandled file request: ' + req.url);
}
setTimeout(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.nextTick is more efficient than setTimeout(, 0)

if (req.url == null) {
t.fail('invalid file request');
} else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('json')) {
callback(null, { data: sprite_json });
} else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('png')) {
callback(null, { data: sprite_png });
} else if (req.url.indexOf('fonts') > -1 && req.url.endsWith('pbf')) {
callback(null, { data: glyph });
} else if (req.url.endsWith('mapbox.satellite')) {
callback(null, { data: source_raster });
} else if (req.url.indexOf('satellite') > -1 && (req.url.endsWith('png') || req.url.endsWith('webp'))) {
callback(null, { data: tile_raster });
} else if (req.url.endsWith('mapbox.mapbox-streets-v7')) {
callback(null, { data: source_vector });
} else if (req.url.indexOf('streets') > -1 && req.url.endsWith('pbf')) {
callback(null, { data: tile_vector });
} else {
t.fail('unhandled file request: ' + req.url);
}
}, 0);
},
ratio: testParams.ratio,
};
Expand Down