标签: chain

如何正确地打破承诺链?

基于这里的问题:jQuery链接和级联然后是什么时候和接受的答案.

我想在某个时刻打破承诺链,但还没有找到正确的方法.有多个 职位 有关这一点,但我还是输了.

从原始问题中获取示例代码:

Menus.getCantinas().then(function(cantinas){ // `then` is how we chain promises
    Menus.cantinas = cantinas;
    // if we need to aggregate more than one promise, we `$.when`
    return $.when(Menus.getMeals(cantinas), Menus.getSides(cantinas));
}).then(function(meals, sides){ // in jQuery `then` can take multiple arguments
    Menus.sides = sides; // we can fill closure arguments here
    Menus.meals = meals;
    return Menus.getAdditives(meals, sides); // again we chain
}).then(function(additives){
    Menus.additives = additives;
    return Menus; // we can also return non promises and chain …
Run Code Online (Sandbox Code Playgroud)

jquery break promise chain

32
推荐指数
3
解决办法
3万
查看次数

$ q promise错误回调链

在下面的代码片段error 1,并success 2会被记录.如果原始延迟被拒绝,我怎样才能传播被调用的错误回调而不是被调用的成功回调.

angular.module("Foo", []);
angular
.module("Foo")
.controller("Bar", function ($q) {
    var deferred = $q.defer();
      deferred.reject();

      deferred.promise
          .then(
              /*success*/function () { console.log("success 1"); },
              /*error*/function () { console.log("error 1"); })
          .then(
              /*success*/function () { console.log("success 2"); },
              /*error*/function () { console.log("error 2"); });
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="Foo">
    <div ng-controller="Bar"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

chain angularjs angular-promise

25
推荐指数
3
解决办法
1万
查看次数

servlet中过滤器和链的用途是什么?

chain.doFilter(req,res);
我们在servlet程序中使用了它.我想知道doFilter()servlet 中该方法的用途是什么?还有什么在Java servlet中使用过滤器和链概念?

java servlets chain servlet-filters

23
推荐指数
3
解决办法
3万
查看次数

如何在JavaScript中创建可链接的函数?

让我们想象这样的功能:

function foo(x) {
    x += '+';
    return x;
}
Run Code Online (Sandbox Code Playgroud)

使用它将是:

var x, y;
x = 'Notepad';
y = foo(x);
console.log(y); // Prints 'Notepad+'.
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种方法来创建可与其他功能链接的功能.

想象一下用法:

var x, y;
x = 'Notepad';
y = x.foo().foo().toUpperCase(); // Prints 'NOTEPAD++'.
console.log(y);
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

javascript return function chain chainable

21
推荐指数
2
解决办法
1万
查看次数

使用QProcess进行管道(或命令链接)

我正在使用Qt和bash,需要执行以下操作:

bash: cat file | grep string
Run Code Online (Sandbox Code Playgroud)

在Qt:

QString cmd = "cat file | grep string";
QProcess *process = new QProcess;
process->start(cmd);
process->waitForBytesWritten();
process->waitForFinished();
qDebug() << process->readAll();
Run Code Online (Sandbox Code Playgroud)

问题在于管道("|"),并且进程没有任何回复.如果没有("|"),就像

"cat file" 
Run Code Online (Sandbox Code Playgroud)

一切都好.我试过smth.喜欢

"cat file \\| grep string", 
"cat file \| grep string" 
Run Code Online (Sandbox Code Playgroud)

但结果是一样的.如果我复制命令并在bash中运行它一切正常.

QString::toAscii().data()
Run Code Online (Sandbox Code Playgroud)

和其他变换也有不好的结果.

c++ shell qt qprocess chain

16
推荐指数
2
解决办法
1万
查看次数

承诺:执行某些事情而不管解决/拒绝?

使用Promises设计模式,是否可以实现以下功能:

 var a, promise

 if promise.resolve
     a = promise.responsevalue;

 if promise.reject
     a = "failed"

 AFTER resolution/rejection. Not ASYNC!!
     send a somewhere, but not asynchronously. //Not a promise
Run Code Online (Sandbox Code Playgroud)

我正在寻找的是类似finallytry - catch情况.

PS:我在NodeJS上使用ES6 Promise polyfill

javascript asynchronous promise chain

16
推荐指数
1
解决办法
9755
查看次数

在RxJava中链接单打

我在我的Android应用程序中使用RxJava和Retrofit向服务器发出网络请求.我正在使用RxJavaCallAdapterFactory,所以我可以让我的改装请求返回单打.在我的代码中,改造对象被命名为'api'.

这里的代码工作正常,但在这个例子中,我需要在制作播放列表之前检索userId.我将userId请求平面映射到API请求,在制作播放列表后,我需要再次使用平面地图将JSON响应转换为可用对象.

public JSONUser me;

public Single<String> getUserId(){

    if(me != null){
        return Single.just(me.getUserId());
    }

    return api.getMe().flatMap(new Func1<JSONUser, Single<String>>() {
        @Override
        public Single<String> call(JSONUser meResult) {
            me = meResult;
            return Single.just(me.getUserId());
        }
    });
}

public Single<Playlist> createPlaylist(String name) {

    final NewPlaylistConfig config = new NewPlaylistConfig(name);

    return getUserId().flatMap(new Func1<String, Single<Playlist>>() {
        @Override
        public Single<Playlist> call(String userId) {
            return api.createPlaylist(userId, config).flatMap(
                    new Func1<JSONPlaylist, Single<? extends SpotifyPlaylist>>() {
                        @Override
                        public Single<? extends Playlist> call(JSONPlaylist data) {
                            return Single.just(new Playlist(data));
                    }
            });
        }
    });
} …
Run Code Online (Sandbox Code Playgroud)

android promise chain rx-java

14
推荐指数
1
解决办法
5026
查看次数

如何将一系列任务路由到芹菜中的特定队列?

当我将任务路由到特定队列时,它可以工作:

task.apply_async(queue='beetroot')
Run Code Online (Sandbox Code Playgroud)

但如果我创建一个链:

chain = task | task
Run Code Online (Sandbox Code Playgroud)

然后我写

chain.apply_async(queue='beetroot')
Run Code Online (Sandbox Code Playgroud)

它似乎忽略了queue关键字并分配给默认的'celery'队列.

如果芹菜支持链中的路由会很好 - 所有任务在同一队列中按顺序执行.

python rabbitmq celery chain

12
推荐指数
3
解决办法
6910
查看次数

芹菜任务链和访问**kwargs

我有类似于此处概述的情况,除了不是使用多个参数链接任务,我想链接返回具有多个条目的字典的任务.

这是 - 非常松散和抽象 - 我正在努力做的事情:

tasks.py

@task()
def task1(item1=None, item2=None):
  item3 = #do some stuff with item1 and item2 to yield item3
  return_object = dict(item1=item1, item2=item2, item3=item3)
  return return_object

def task2(item1=None, item2=None, item3=None):
  item4 = #do something with item1, item2, item3 to yield item4
  return_object = dict(item1=item1, item2=item2, item3=item3, item4=item4)
  return return_object
Run Code Online (Sandbox Code Playgroud)

从ipython开始,我可以单独和异步地调用task1,没有任何问题.

我也可以单独调用task2,task1返回的结果为双星参数:

>>res1 = task1.s(item1=something, item2=something_else).apply_async()
>>res1.status
'SUCCESS'
>>res2 = task2.s(**res1.result).apply_async()
>>res2.status
'SUCCESS
Run Code Online (Sandbox Code Playgroud)

但是,我最终想要实现的是与上面相同的最终结果,但是通过链,在这里,我无法弄清楚如何将task2实例化而不是使用task1返回的(位置)参数,而是使用task1.result作为**kwargs:

chain_result = (task1.s(item1=something, item2=something_else) | task2.s()).apply_async()  #THIS DOESN'T WORK! …
Run Code Online (Sandbox Code Playgroud)

python kwargs celery chain

12
推荐指数
2
解决办法
5246
查看次数

承诺:忽略捕获并返回链

是否可以忽略捕获并返回链?

promiseA()        // <-- fails with 'missing' reason
  .then(promiseB) // <-- these are not going to run 
  .then(promiseC)
  .catch(function(error, ignore){
     if(error.type == 'missing'){
        ignore()  // <-- ignore the catch and run promiseB and promiseC
     }
  })
Run Code Online (Sandbox Code Playgroud)

这样的事情可能吗?

javascript ignore promise chain

12
推荐指数
1
解决办法
1万
查看次数