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

why pinging run with mainthread #140

Open
spencer627 opened this issue Nov 2, 2022 · 0 comments
Open

why pinging run with mainthread #140

spencer627 opened this issue Nov 2, 2022 · 0 comments

Comments

@spencer627
Copy link

why pinging run with mainthread? in children thread will call bug?
The code :

  • (void)pingWithBlock:(void (^)(BOOL isSuccess, NSTimeInterval latency))completion
    {
    //NSLog(@"pingWithBlock");
    if (completion)
    {
    // copy the block, then added to the blocks array.
    @synchronized(self)
    {
    [self.completionBlocks addObject:[completion copy]];
    }
    }

    if (!self.isPinging)
    {
    // MUST make sure pingFoundation in mainThread
    __weak __typeof(self)weakSelf = self;
    if (![[NSThread currentThread] isMainThread]) {
    dispatch_sync(dispatch_get_main_queue(), ^{
    __strong __typeof(weakSelf)strongSelf = weakSelf;
    [strongSelf startPing];
    });
    }
    else
    {
    [self startPing];
    }
    }
    }

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

1 participant