Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beach_await #51

Closed
AppleDP opened this issue Mar 18, 2019 · 1 comment
Closed

beach_await #51

AppleDP opened this issue Mar 18, 2019 · 1 comment
Assignees

Comments

@AppleDP
Copy link

AppleDP commented Mar 18, 2019

像下面这种模拟网络请求调用,如果 -func1 睡眠的时间比 -func2 睡眠的时间长时,为什么不会执行到NSLog(@"num = %@ -- error: %@",num,error);这句代码?

co_launch(^{
NSLog(@"co_launch1 前 -- %@",[NSThread currentThread]);
NSNumber *num;
NSError *error;
NSArray *array = batch_await(@[[self func1], [self func2]]);
NSLog(@"num = %@ -- error: %@",num,error);
co_unpack(&num, &error) = array[0];
NSLog(@"co_launch1 后 -- %@",[NSThread currentThread]);
});

  • (COPromise *)func1 {
    return [COPromise promise:^(COPromiseFullfill _Nonnull fullfill, COPromiseReject Nonnull reject) {
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
    NSLog(@"前 func1 -- %@",[NSThread currentThread]);
    [NSThread sleepForTimeInterval:5.0];
    fullfill(co_tuple(@(10), [NSError errorWithDomain:@"co
    " code:100 userInfo:nil]));
    NSLog(@"后 func1 -- %@",[NSThread currentThread]);
    });
    }];
    }

  • (COPromise *)func2 {
    return [COPromise promise:^(COPromiseFullfill _Nonnull fullfill, COPromiseReject _Nonnull reject) {
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
    NSLog(@"前 func2 -- %@",[NSThread currentThread]);
    [NSThread sleepForTimeInterval:3.0];
    fullfill(nil);
    NSLog(@"后 func2 -- %@",[NSThread currentThread]);
    });
    }];
    }

@NianJi
Copy link
Collaborator

NianJi commented Mar 18, 2019

Duplicate, #25

And it's already fixed. upgrade to 1.1.0

@NianJi NianJi closed this as completed Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants