Skip to content

Commit

Permalink
fix batch_await return null when error, should be error object, fix a…
Browse files Browse the repository at this point in the history
  • Loading branch information
NianJi committed Mar 3, 2019
1 parent cc0dc88 commit dabf22b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ static id testPromise2() {
return promise;
}

static COPromise *testPromise11() {
return [COPromise promise:^(COPromiseFullfill _Nonnull fullfill, COPromiseReject _Nonnull reject) {

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
fullfill(@"1");
});
}];
}
static COPromise *testPromise12() {
return [COPromise promise:^(COPromiseFullfill _Nonnull fullfill, COPromiseReject _Nonnull reject) {

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
fullfill(@"2");
});
}];
}
static COPromise *testPromise13() {
return [COPromise promise:^(COPromiseFullfill _Nonnull fullfill, COPromiseReject _Nonnull reject) {

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
reject([NSError errorWithDomain:@"aa" code:3 userInfo:@{}]);
});
}];
}

@interface Test123 : NSObject
{
dispatch_block_t _block;
Expand Down Expand Up @@ -180,5 +205,26 @@ static id testPromise3() {
});
});

it(@"batch await test", ^{
co_launch(^{

NSArray *results = batch_await(@[
testPromise11(),
testPromise12(),
testPromise13(),
]);
expect(results[0]).to.equal(@"1");
expect(results[1]).to.equal(@"2");
expect(results[2]).to.equal([NSError errorWithDomain:@"aa" code:3 userInfo:@{}]);

});

waitUntil(^(DoneCallback done) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
done();
});
});
});

});
SpecEnd
2 changes: 1 addition & 1 deletion coobjc/api/COCoroutine.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ id co_await(id awaitable) {
}]
catch:^(NSError * _Nonnull error) {
co.lastError = error;
[chan send_nonblock:nil];
[chan send_nonblock:error];
}];

[chan onCancel:^(COChan * _Nonnull chan) {
Expand Down

0 comments on commit dabf22b

Please sign in to comment.