Skip to content

lucianomarisi/Runner

Repository files navigation

Runner

Build Status codecov.io

Easily execute a block at specific time intervals.

Installation

Either

OR

  • Add the files inside the Runner folder to your project

Examples

Execute a predefined set of points

// Generate some points
var mockPoints = [Point]()
let numberOfPoints = 10
let totalTime = 1.0
for index in 0...numberOfPoints {
  let timestamp = NSTimeInterval(index) * totalTime / Double(numberOfPoints)
  let mockPoint = Point(timestamp: timestamp, value: Double(index))
  mockPoints.append(mockPoint)
}

// Execute blocks at the times from the mocked points
let runner = Runner()
runner.startWithMockPoints(mockPoints) { (point) -> Void in
  NSLog("\(point.value)")
}

This will produce the following logs:

Execute points using a function

// Define function to generate points
func sineSignal(nextTimestamp: NSTimeInterval) -> Point {
  let signalFrequency = 1.0
  let amplitude = 2.0
  let offset = 0.5
  let phaseShift = 0.2
  let value = amplitude * sin(nextTimestamp * signalFrequency + phaseShift) + offset
  return Point(timestamp: nextTimestamp, value: value)
}

let runner = Runner()
// Start executing points
runner.startWithFunction(sineSignal) { (point) -> Void in
  NSLog("\(point.value)")
}

// Stop executing points
runner.stop()

This will produce the following logs:

About

Execute a block at specific time intervals

Resources

Stars

Watchers

Forks

Packages

No packages published