-
Notifications
You must be signed in to change notification settings - Fork 65
Home
Carlyle-Lee edited this page Jul 31, 2020
·
21 revisions
dependencies {
implementation 'com.iqiyi.taskmanager:taskmanager:1.3.7'
}
TM.postAsync(Runnable); // To run on background thread
TM.postAsyncDelay(Runnable, int);
TM.postSerial(Runnable , String groupName);// Runnable of same group will run in FIFO order.
TM.postUI(Runnable); // To run on UI thread.
TM.postUIDelay(Runnable, int delay);//
//declair a new task to run on background thread.
new Task(){
@Override
public void doTask() {
}
}.postAsync();
流式调用用途: 可以在方法调用返回流式调用对象,从而替代callback 的设计。
LinkedList<LinkedList<String[]>> linl = new LinkedList<>();
TM.forEach(linl)
.preCall(value -> Log.d(TAG," L1 "+value))
.preCall(value -> Log.d(TAG, "L1-1 " + value))
.afterCall(value -> Log.d(TAG, "ATF L1-1 " + value))
// 数据转换
.shiftT(ShiftFactory::create)
.preCall(value -> Log.d(TAG," L2 "+value))
.preCall(value -> Log.d(TAG," L2-2 "+value))
// 数据转换
.shiftT(ShiftFactory::create)
.preCall(value -> Log.d(TAG," L3 "+value))
// 任务执行
.call(value -> Log.e(TAG," L3 called "+value));
TM.just(1)
.preCall(value -> Log.d(TAG, "preL1 : just " + value))
.shiftT(value -> ShiftFactory.create((value +1)+" int to String "))
.preCall(value -> Log.d(TAG, "preL2 "+ value))
.preCall(value -> Log.d(TAG,"preL3 " + value))
.afterCall(value -> Log.d(TAG,"aft L2 "+value))
.afterCall(value -> Log.d(TAG,"aft L3 " + value))
.afterCall(value -> Log.d(TAG,"aft L4 " + value))
.callAsync(value -> Log.e(TAG, "called " + value));
请参参考Demo 中的相关test 代码。例如 DependantTest、NeedSyncTest 等等。
Please refer to test files in demo for examples such as "DependantTest.java", "NeedSyncTest .java" , etc...