From c7a47558084b200d1db3dbb79dba4ebca0bbe10e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 29 Mar 2017 09:27:21 -0600 Subject: [PATCH] If Workspace.open finds existing item, yield event loop This ensures that the function always behaves asynchronously regardless of the state of the workspace. /cc @maxbrunsfeld Signed-off-by: Antonio Scandurra --- src/workspace.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/workspace.js b/src/workspace.js index 8d346e9bd..6c9621b28 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -670,8 +670,12 @@ module.exports = class Workspace extends Model { if (pane) item = pane.itemForURI(uri) } - // Create an item if one was not found. - if (!item) { + // If an item is already present, yield the event loop to ensure this method + // is consistently asynchronous regardless of the workspace state. If no + // item is present, create one. + if (item) { + await Promise.resolve() + } else { item = await this.createItemForURI(uri, options) if (!item) return