You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question "how to stop the BFTask chain, break from the chain execution"
See Commnets
BFTask *task = [_model getX1Task];
[[task continueWithBlock:^id(BFTask *task) {
if (task.error || task.exception || task.isCancelled) {
return nil;
} else {
NSDictionary *dic = (NSDictionary *)task.result;
if ([dic isKindOfClass:[NSDictionary class]])
{
if ([self checkX1OK])
{
return [_model getX2Task];
}
else
{
//here I want break
//so i return nil, but I found the continueWithBlock will still return a new task have a nil result, so the chain automaticall go to below
return nil
}
}
}
}] continueWithBlock:^id(BFTask *task) {
//but the code come here, even the before task is return nil
if (task.error || task.exception || task.isCancelled) {
return nil;
}
else {
if ([self checkX2OK])
{
return [_model getX3Task];
}
else
{
//here want break
//so i return nil
return nil
}
}
}] ;
I found why the nil case return default task in BFTask's method continueWithExecutor:withBlock:
- (BFTask *)continueWithExecutor:(BFExecutor *)executor
withBlock:(BFContinuationBlock)block {
BFTaskCompletionSource *tcs = [BFTaskCompletionSource taskCompletionSource];
............................
//because the result is nil, so it's not a BFTask class
if ([result isKindOfClass:[BFTask class]]) {
[(BFTask *)result continueWithBlock:^id(BFTask *task) {
...........
return nil;
}];
} else {
tcs.result = result; //so nil result will go here
}
}];
};
......
return tcs.task;
//so even a nil result will return a default task which is create by BFTaskCompletionSource
}
I have thought a way like this to add one stop:BOOL in the block
typedef id(^BFContinuationWithStopBlock)(BFTask *task, BOOL *stop);
so I can mark &stop = YES, when I want to stop the execution, what are your opinions?
The text was updated successfully, but these errors were encountered:
Hi Guys
I have a question "how to stop the BFTask chain, break from the chain execution"
See Commnets
I found why the nil case return default task in BFTask's method
continueWithExecutor:withBlock:
I have thought a way like this to add one stop:BOOL in the block
typedef id(^BFContinuationWithStopBlock)(BFTask *task, BOOL *stop);
so I can mark
&stop = YES
, when I want to stop the execution, what are your opinions?The text was updated successfully, but these errors were encountered: