-
-
Save TooTallNate/3751570 to your computer and use it in GitHub Desktop.
Apple's CFRunLoop and node's libuv event loop playing nice together :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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