From 290fd42218e9ad2e172ac0e30c5cedb25ea64cc7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 19 Jul 2017 14:31:45 -0700 Subject: [node] Protect against synchronous request implementations --- platform/node/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/node/index.js b/platform/node/index.js index 54ba5c0dc6..e36a47943d 100644 --- a/platform/node/index.js +++ b/platform/node/index.js @@ -4,6 +4,7 @@ var mbgl = require('../../lib/mapbox_gl_native.node'); var constructor = mbgl.Map.prototype.constructor; +var process = require('process'); var Map = function(options) { if (!(options instanceof Object)) { @@ -19,7 +20,12 @@ var Map = function(options) { return new constructor(Object.assign(options, { request: function(req) { request(req, function() { - req.respond.apply(req, arguments); + var args = arguments; + // Protect against `request` implementations that call the callback synchronously. + // http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony + process.nextTick(function() { + req.respond.apply(req, args); + }); }); } })); -- cgit v1.2.1