Promise chain continues before inner promise is resolved <p>Similar question to <a href="http://stackoverflow.com/questions/29699372/promise-resolve-before-inner-promise-resolved">Promise resolve before inner promise resolved</a> but I can't get it to work nontheless.</p> <p>Every time I think I understand promises, I prove myself wrong!</p> <p>I have functions that are written like this</p> <pre><code>function getFileBinaryData () { var promise = new RSVP.Promise(function(resolve, reject){ var executorBody = { url: rootSite + sourceRelativeUrl + "/_api/web/GetFileByServerRelativeUrl('" + fileUrl + "')/$value", method: "GET", binaryStringResponseBody: true, success: function (fileData) { resolve(fileData.body); }, error: function (argument) { alert("could not get file binary body") } } sourceExecutor.executeAsync(executorBody); }); return promise; } function copyFileAction (fileBinaryData) { var promise = new RSVP.Promise(function(resolve, reject){ var executorBody = { url: rootSite + targetWebRelativeUrl + "/_api/web/GetFolderByServerRelativeUrl('" + targetList + "')/Files/Add(url='" + fileName + "." + fileExt + "', overwrite=true)", method: "POST", headers: { "Accept": "application/json; odata=verbose" }, contentType: "application/json;odata=verbose", binaryStringRequestBody: true, body: fileBinaryData, success: function (copyFileData) { resolve(); }, error: function (sender, args) { } } targetExecutor.executeAsync(executorBody); }); return promise; } </code></pre> <p>that I try to chain like this</p> <pre><code>$.getScript("/_layouts/15/SP.RequestExecutor.js") .then(patchRequestExecutor) .then(function(){ sourceExecutor = new SP.RequestExecutor(sourceFullUrl); targetExecutor = new SP.RequestExecutor(targetList); }) .then(getFileInformation) .then(getFileBinaryData) .then(copyFileAction) .then(getTargetListItem) .then(updateTargetListItem) .catch(function (sender, args) { }); </code></pre> <p>or like this</p> <pre><code>$.getScript("/_layouts/15/SP.RequestExecutor.js") .then(patchRequestExecutor) .then(function(){ sourceExecutor = new SP.RequestExecutor(sourceFullUrl); targetExecutor = new SP.RequestExecutor(targetList); }) .then(function(){ return getFileInformation(); }) .then(function(){ return getFileBinaryData(); }) .then(function(binaryData){ return copyFileAction(binaryData) }) .then(function(){ return getTargetListItem(); }) .then(function(listItem){ return updateTargetListItem(listItem); }); </code></pre> <p>The problem though is that even if I return new promises, the execution continues down the chain before any of the inner promises are resolved. How come? Shouldn't it wait until the asynchronous request has succeeded and <code>resolve()</code> is called in the <code>success</code> callback?</p>