Navigation Menu

Skip to content

Commit

Permalink
also have a way to avoid stack overflows if possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtaco committed Jan 24, 2012
1 parent 47d6dc2 commit 6e38a46
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
25 changes: 23 additions & 2 deletions lib/coffee-script/tame.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion src/tame.coffee
Expand Up @@ -39,12 +39,28 @@ makeDeferReturn = (obj, defer_args, id) ->

ret

#-----------------------------------------------------------------------
#
# Tick Counter --
# count off every mod processor ticks
#
__c = 0

tickCounter = (mod) ->
__c++
if (__c % mod) == 0
__c = 0
true
else
false

#-----------------------------------------------------------------------
# Deferrals
#
# A collection of Deferrals; this is a better version than the one
# that's inline; it allows for tame tracing
#

class Deferrals

constructor: (k) ->
Expand All @@ -53,7 +69,11 @@ class Deferrals
@ret = null

_fulfill : ->
@continuation @ret if --@count == 0
if --@count == 0
if tickCounter 500
process.nextTick (=> @continuation @ret)
else
@continuation @ret

defer : (args) ->
@count++
Expand Down
8 changes: 8 additions & 0 deletions test/tame_advanced.coffee
Expand Up @@ -64,3 +64,11 @@ if require?
for s in slots
ok = false unless s == 7
cb(ok, {})

##----------------------------------------------------------------------

atest "stack protector", (cb) ->
noop = (cb) -> cb()
for i in [0..10000]
await noop defer()
cb(true, {})

0 comments on commit 6e38a46

Please sign in to comment.