Skip to content

Commit

Permalink
Make the timers cancellable
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Jul 19, 2016
1 parent 18cf039 commit a26ffb4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function makePromisable (parent, prop) {
})
// Return the returnValue through valueOf
promise.valueOf = () => returnValue
promise.toString = () => returnValue
return promise
}
})
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ describe('core', function () {
throw new Error('Random error')
}).catch(() => done())
})

it('Can clear properly the timer', function (done) {
const coolGlobal = allora(global)
const timer = coolGlobal.setTimeout(200)

var count = 0

timer.then(_ => count++)

clearTimeout(timer.valueOf())

setTimeout(function () {
expect(count).to.be.equal(0)
done()
}, 1000)
})
})

0 comments on commit a26ffb4

Please sign in to comment.