QuickAccess类

-com.tencent.mm.vending.pipeline.QuickAccess类提供了一组便利静态接口,方便使用。

  • pipeline()函数组 - 便捷的pipeline创建,例如:
pipeline("username", "password")
            .next(...)
            ...
  • tuple函数组 - 便捷创建Tuple对象:
Tuple tuple = tuple("arg1", "arg2", 3, 4);
  • Mario接口 - 包括mario(), pending(), resume(), interrupt(), progress()
// interrupt
pipeline().$logic(new Functional<Void, Void>() {
    @Override
    public Void call(Void nil) {
        interrupt(-1);
        return nil;
    }
})

// pending and resume
pipeline().$logic(new Functional<String, Void>() {
    @Override
    public String call(Void nil) {
        final Mario mario = pending();
        pipeline().$heavyWork(new Functional<Void, Void>() {
            @Override
            public Void call(Void nil) {
                // some heavy work
                resume(mario, "work done");
            }
        }
        return null;  // this result will be replaced by pipeline.$heavyWork  returns
    }
})
  • bridge() - pipeline的桥接,将另一个pipeline的结果作为当前Functional的返回,相当于pending()resume的便捷函数:
pipeline().$logic(new Functional<String, Void>() {
    @Override
    public String call(Void nil) {
        bridge(pipeline().$heavyWork(new Functional<String, Void>() {
            @Override
            public String call(Void aVoid) {
                // some heavy work
                return "work done ";
            }
        });
        return null; // this result will be replaced by pipeline.$heavyWork returns
    }
})
  • $()函数组 - 用于将Functional封装为携带指定SchedulerSchedulerFunctional,包括$ui(), $logic(), $heavyWork()等。
  • list(T ... args) - 创建ImmList<T>的便捷接口
  • repipeable() - 将一个PipeableTerminal对象转变为可以继续Pipeable的对象,实际上是创建了新的pipeline对象。
  • parallels()函数组 - 将多个Functional类组装成ParallelsFunctional,支持多个Functional的并发执行。
// parallels
pipeline(0)
    // run parallels functional
    .next(
        parallels(new Functional<Integer, Integer>() {
                @Override
                public Integer call(Integer integer) {
                    VendingLog.i(TAG, "parallels 1 %s", Looper.myLooper());
                    return 1;
                }
            }, new Functional<Tuple2<Integer, Integer>, Integer>() {
                @Override
                public Tuple2<Integer, Integer> call(Integer integer) {
                    VendingLog.i(TAG, "parallels 2 %s", Looper.myLooper());
                    return Tuple2.make(2, 2);
                }
            }, $logic(new Functional<Object, Integer>() {
                    @Override
                    public Object call(Integer integer) {
                        VendingLog.i(TAG, "parallels 3 sleep 1000 %s", Looper.myLooper());
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        return 3;
                    }
                })
            ))
    // process parallels functional results
    .$ui(
        new Functional<Void, Tuple3<Integer,Tuple2<Integer,Integer>,Object>>() {
            @Override
            public Void call(
                Tuple3<Integer, Tuple2<Integer, Integer>, Object> integerTuple2ObjectTuple3) {
                VendingLog.i(TAG, "parallels result %s %s %s"
                        , integerTuple2ObjectTuple3.$1()
                        , integerTuple2ObjectTuple3.$2()
                        , integerTuple2ObjectTuple3.$3());
                return nil;
            }
        });

results matching ""

    No results matching ""