Okay, once again I’m deep in the weeds here.
I’m just wrapping my brain around the scope of the “tick” command. For the longest time, I thought each object (array, etc) I was ticking through had its own tick, but I finally realized that, unless I pass a unique symbol, everything shares the global tick. This led to some subtle and previously baffling bugs in my code.
My question is this:
If I write a method that calls the global tick, does that affect the tick count in the code calling that method? Or does each method get its own scoped tick counter?
Okay, I answered my own question. Tick is globally scoped, across all methods, containing structures, etc.:
define :scopedtick do |outertick|
localtick = tick
puts "localtick: ", localtick
puts "outertick: ", outertick
end
4.times do
outertick = tick
scopedtick outertick
end
I guess I’m going to have to be more careful with ticking.
Actually, each thread gets its own scoped tick counter, so inside e.g. a live_loop
(which runs in a separate thread), you’ll get a separate tick counter.
But outside of any threaded constructs, all unnamed ticks would be shared.
Thanks for that clarification. That makes alot of sense.
I take it that named ticks have the same scoping rules, so tick(:foo) would span functions and blocks but not threads?
I wasn’t sure about the answer to that, but I ran a test and it seems to be the case: even named ticks are local to their thread/live_loop (but do span functions/blocks).
Thanks for the clarity.