Tributary and setTimeout

10 views
Skip to first unread message

Mike Wolf

unread,
Jan 23, 2015, 3:46:05 PM1/23/15
to trib...@googlegroups.com
Here's an inlet that shows the problem with setTimeout, and a solution.
http://tributary.io/inlet/901fafe4799da4ddf1c3

#To see the problem, run this inlet, with console open
#Type characters in a comment line and you will see new instances created, and restart sequence
#Then set the value of normalCallback to true and type some more comment characters and you will see the problem
#My proposed workaround could be made part of tributary and only the modified setTimeout exposed to the user

#Make it easy to see in console what just happened
#Nice to make this a persistent config preference
console.clear()

#I am using this instance number to show the problem with callbacks
#Might be useful to have this happen automatically
tributary.TBInstance ?= 0
instance = ++tributary.TBInstance

#How many times has the callback been called in this instance
seq = 1

#change behavior for callbacks: toggle true or false
normalCallback = false  
callback = () -> 
  console.log "I am a callback #{seq++} for instance #{instance}"
  #If normalCallback is false, then setTimeout called in usual way
  if normalCallback 
    setTimeout callback, 1000
  else
    #conditional callback, only if we are latest instance
    if instance is tributary.TBInstance
   setTimeout callback, 1000
    
    
setTimeout callback, 1000

Ian Johnson

unread,
Feb 15, 2015, 11:21:00 PM2/15/15
to Mike Wolf, trib...@googlegroups.com
nice, yes one of the interesting problems with tributary is that code that has global side effects can be problematic.
This is why I started doing the esprima modification of the tributary code so we could cache d3.json calls.
Geoffrey also started work on limiting while loops automatically in the same way so you wouldnt accidentally crash your browser window with a malformed while/for loop.

this should be able to be accomplished by looking at the inline-console and ajax-caching plugins:

i've played with different ways to introduce control over animation but haven't settled on a great one yet.
this was one: https://github.com/enjalot/tributary/wiki/Plugins:-Play (api has partially changed...)
this is another: http://tributary.io/inlet/6862777 look for "tributary.anim(...)"

--
You received this message because you are subscribed to the Google Groups "Tributary" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tributary+...@googlegroups.com.
Visit this group at http://groups.google.com/group/tributary.
For more options, visit https://groups.google.com/d/optout.



--
Ian Johnson - 周彦
Reply all
Reply to author
Forward
0 new messages