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
封装为携带指定Scheduler
的SchedulerFunctional
,包括$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;
}
});