Promise chain continues before inner promise is resolved

后端 未结 1 1089
刺人心
刺人心 2020-12-02 03:07

Similar question to Promise resolve before inner promise resolved but I can\'t get it to work nontheless.

Every time I think I understand promises, I prove myself wr

1条回答
  •  被撕碎了的回忆
    2020-12-02 03:20

    You've done nothing wrong here. This is jQuery's fault, as so often1.

    The problem is that jQuery is not Promises/A+ compatible (until v 3.0), and fails to adopt promises/thenable from other implementations than its own. So when your callbacks do return RSVP promises, jQuery just treats them as values to fulfill with, instead of waiting for them.
    You could cast all of your promises to a jQuery deferred and it would work, but you really don't want that. To get the standard Promise behaviour (as offered by RSVP) to work, you will need to avoid jQuery's buggy then. This can easily be done:

    RSVP.Promise.resolve($.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)
        …
    

    0 讨论(0)
提交回复
热议问题