Skip to content

why pinging run with mainthread #140

Description

@spencer627

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];
    }
    }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions