, "Promise". , , :
, async , , . -, . , .
:
typedef void (^completion_block_t)(id result);
testie, async, :
- (void) asyncFooWithCompletion:(completion_block_t)completionHandler;
:
- (void) testAsyncFooWithCompletion
{
RXPromise* handlerPromise = [RXPromise new];
[foo asyncFooWithCompletion:^(id result){
...
if (result is expected) {
[handlerPromise fulfillWithValue:@"OK"];
}
else {
[handlerPromise rejectWithReason:@"Unexpected result"];
}
}];
: asyncFooWithCompletion: , - . .
, . .
[handlerPromise setTimeout:5.0];
[handlerPromise.thenOn(dispatch_get_main_queue(), nil,
^id(NSError* error) {
ADD_FAILURE() << [[error description] UTF8String];
return error;
})
runLoopWait];
}