Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created September 19, 2012 19:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/3751570 to your computer and use it in GitHub Desktop.
Save TooTallNate/3751570 to your computer and use it in GitHub Desktop.
Apple's CFRunLoop and node's libuv event loop playing nice together :)
snow-leopard:~ nrajlich$ node t
JS interval!
JS interval!
NSTimer invokation! <NSCFTimer: 0x18c5a20>
JS interval!
JS interval!
NSTimer invokation! <NSCFTimer: 0x18c5a20>
JS interval!
JS interval!
NSTimer invokation! <NSCFTimer: 0x18c5a20>
JS interval!
JS interval!
NSTimer invokation! <NSCFTimer: 0x18c5a20>
JS interval!
JS interval!
NSTimer invokation! <NSCFTimer: 0x18c5a20>
var $ = require('./NodObjC')
var cf = require('./node-cf')
var assert = require('assert')
var loop = cf.ref()
$.import('Foundation')
var pool = $.NSAutoreleasePool('alloc')('init')
var Obj = $.NSObject.extend('Obj')
, invokeCount = 0
Obj.addMethod('sel:', 'v@:@', function (self, _cmd, timer) {
assert.equal('Info', timer('userInfo').toString())
console.log('NSTimer invokation!', timer);
if (++invokeCount == 5) {
timer('invalidate')
process.exit(0)
}
}).register()
var timer = $.NSTimer('scheduledTimerWithTimeInterval', 0.5
,'target', Obj('alloc')('init')
,'selector', 'sel:'
,'userInfo', $('Info')
,'repeats', 1)
process.on('exit', function () {
assert.equal(invokeCount, 5)
})
setInterval(function () {
console.log('JS interval!');
}, 250);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment