Skip to content

Commit

Permalink
fix(COPromise.m): fix promise chained call reject crash
Browse files Browse the repository at this point in the history
fix promise chained call reject crash

fix alibaba#62
  • Loading branch information
pengyutang125 committed Mar 29, 2019
1 parent 80b2a3d commit d72e79f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ static id testPromise3() {


waitUntil(^(DoneCallback done) {
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
expect(val).to.equal(11);
done();
});
Expand Down Expand Up @@ -735,4 +735,19 @@ static id testPromise3() {
});

});

describe(@"https://github.com/alibaba/coobjc/issues/62", ^{
it(@"fix crash", ^{
[[[COPromise promise:^(COPromiseFulfill _Nonnull fullfill, COPromiseReject _Nonnull reject) {
fullfill(@"step 1");
}] then:^id _Nullable(id _Nullable value) {
NSLog(@"eIIIIIII = %@", value);
return [COPromise promise:^(COPromiseFulfill _Nonnull fullfill, COPromiseReject _Nonnull reject) {
reject([NSError errorWithDomain:@"step 2" code:99 userInfo:nil]);
}];
}] catch:^(NSError * _Nonnull error) {
NSLog(@"eIIIIIII = %@", error.domain);
}];
});
});
SpecEnd
2 changes: 1 addition & 1 deletion coobjc/promise/COPromise.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ - (COPromise *)chainedPromiseWithFulfill:(COPromiseChainedFulfillBlock)chainedFu
[(COPromise *)value observeWithFulfill:^(id _Nullable value) {
[promise fulfill:value];
} reject:^(NSError *error) {
[promise reject:value];
[promise reject:error];
}];
} else {
if (isReject) {
Expand Down

0 comments on commit d72e79f

Please sign in to comment.