在Promise中更直接地使用函数 [英] Using a function more directly in a promise

查看:98
本文介绍了在Promise中更直接地使用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种表达方式:

    imagePFFileFromUrl(exampUrl) // (returns a promise)
    .then(function(xxx))
        // that syntax gives you the results of the
        // imagePFFileFromUrl inside the variable xxx.
        // I then use it in another function which
        // returns another promise...
        {
        return saveImageFile(xxx, anotherArgument) // (returns a promise)
        })
    .then(function(savedPFFile)

更像这样..

    imagePFFileFromUrl(exampUrl)
    .then(saveImageFile(...the results from imagePFFileFromUrl ...))
    .then(function(savedPFFile)

何时使用诺言?

推荐答案

您的.then()需要具有1或2个回调函数.如果为1,则采用承诺的已解决值.如果有两个,则第二个接受承诺的拒绝值.所以,不,您不能做您想做的事情.

Your .then()'s need to have 1 or 2 call back functions. If there is 1, it takes in the resolved value of the promise. If there are two, the second takes the rejected value of the promise. So, no, you can't do what you are trying to do.

这是该模式的很好的示例,带有两个参数,请注意return synchUsers

Here's a good example of the pattern, with two arguments, notice at return synchUsers

这篇关于在Promise中更直接地使用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆