Skip to content

Instantly share code, notes, and snippets.

@own2pwn
Forked from hfossli-agens/gist:4676773
Created November 25, 2017 13:38
Show Gist options
  • Select an option

  • Save own2pwn/21a64eddd8f4f53ab89251835bfdf9da to your computer and use it in GitHub Desktop.

Select an option

Save own2pwn/21a64eddd8f4f53ab89251835bfdf9da to your computer and use it in GitHub Desktop.

Revisions

  1. @hfossli hfossli created this gist Jan 30, 2013.
    18 changes: 18 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    static void dispatch_repeated_internal(dispatch_time_t firstPopTime, double intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
    {
    __block BOOL shouldStop = NO;
    dispatch_time_t nextPopTime = dispatch_time(firstPopTime, (int64_t)(intervalInSeconds * NSEC_PER_SEC));
    dispatch_after(nextPopTime, queue, ^{
    work(&shouldStop);
    if(!shouldStop)
    {
    dispatch_repeated_internal(nextPopTime, intervalInSeconds, queue, work);
    }
    });
    }

    void dispatch_repeated(double intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
    {
    dispatch_time_t firstPopTime = dispatch_time(DISPATCH_TIME_NOW, intervalInSeconds * NSEC_PER_SEC);
    dispatch_repeated_internal(firstPopTime, intervalInSeconds, queue, work);
    }