Skip to content

Commit

Permalink
Added clock example.
Browse files Browse the repository at this point in the history
  • Loading branch information
vic committed Aug 14, 2012
1 parent 79df6ed commit 27f258f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var NoR = require('../lib/NoR.js')

var clock = new NoR(function(signal, enable){}, function(time){
var timeout, enable = this.enable, signal = this.signal
tick = function() {
signal(! signal() )
timeout = setTimeout(tick, time())
}
enable.subscribe(function(enable){
if(enable) {
tick()
} else if(timeout){
clearTimeout(timeout)
}
})
})

var counter = new NoR(function(clock, count){
count( count() + 1 )
}, function(){
// mark the count cell so it doent
// trigger counter execution again
// mark it as an outputOnly cell.
this.count.isOutput = true
})

var c = clock(true, false, 300)
var n = counter(c.signal, 0)
n.count.subscribe(function(time){
console.log("SIGNAL on time", time, c.signal())
if(time > 9) {
c.enable(false)
}
})


c.enable(true)

0 comments on commit 27f258f

Please sign in to comment.