Skip to content

Instantly share code, notes, and snippets.

@seanlilmateus
Created November 8, 2012 14:22
Show Gist options
  • Save seanlilmateus/4039077 to your computer and use it in GitHub Desktop.
Save seanlilmateus/4039077 to your computer and use it in GitHub Desktop.
Rubymotion NSOperationQueue
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds).tap do |win|
win.rootViewController = AsyncController.alloc.init
win.makeKeyAndVisible
end
true
end
end
class AsyncController < UIViewController
def thread1
10.times { |i| NSLog("\t Thread1: %@", i) }
end
def thread2
20.times { |i| NSLog("\t\t Thread2: %@", i) }
end
def thread3
30.times { |i| NSLog("\t\t\t Thread3: %@", i) }
end
def viewDidLoad
self.view.backgroundColor = UIColor.whiteColor
@queue = NSOperationQueue.new
@queue.maxConcurrentOperationCount = 3
@queue.name = "threads operation"
operation1 = NSInvocationOperation.alloc.initWithTarget(self, selector: :thread1, object:nil)
operation2 = NSInvocationOperation.alloc.initWithTarget(self, selector: :thread2, object:nil)
operation3 = NSInvocationOperation.alloc.initWithTarget(self, selector: :thread3, object:nil)
@queue.addOperation(operation1)
@queue.addOperation(operation2)
@queue.addOperation(operation3)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment