Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: numist/NNKit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9143025042d76f94f51f9e2cdd72e26cb2b3a9e1
Choose a base ref
...
head repository: numist/NNKit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6107640b7d051bb34431dcf01030815537937266
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Oct 17, 2013

  1. Quieter polling objects, updated timing semantics

    The NNPollingObject superclass no longer logs anything, it is up to each subclass to perform any timing or liveness checks that they may need.
    The poll timing has also changed. No longer is the time spent performing the last iteration credited to the next interval, each iteration begins a full interval after the previous completed. In addition, notification dispatch blocks execution of the caller, yielding the worker queue to other jobs on the runloop until the main thread has finished processing the notification.
    numist committed Oct 17, 2013
    Copy the full SHA
    6107640 View commit details
Showing with 9 additions and 10 deletions.
  1. +9 −10 NNKit/Actors/NNPollingObject.m
19 changes: 9 additions & 10 deletions NNKit/Actors/NNPollingObject.m
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@

#import "NNPollingObject.h"

#import "despatch.h"


@interface NNPollingObject ()

@@ -50,22 +52,15 @@ - (instancetype)init;

- (void)workerLoop;
{
NSDate *start = [NSDate date];

[self main];

if (self.interval <= 0.0) {
NSLog(@"Interval is negative, disabling polling loop for %@", self);
NSTimeInterval interval = self.interval;
if (interval <= 0.0) {
return;
}

double elapsed = [[NSDate date] timeIntervalSinceDate:start];
if (elapsed > self.interval) {
NSLog(@"Worker loop interation took %f seconds (interval %f)!", elapsed, self.interval);
}

__weak id weakSelf = self;
double delayInSeconds = MAX(self.interval - elapsed, 0.0);
double delayInSeconds = interval;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, self.queue, ^(void){
id self = weakSelf;
@@ -75,9 +70,13 @@ - (void)workerLoop;

- (void)postNotification:(NSDictionary *)userInfo;
{
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:[[self class] notificationName] object:self userInfo:userInfo];
dispatch_group_leave(group);
});
while(!despatch_group_yield(group));
}

- (void)main;