choochoo.js — A timing library.

Adam R Turner
2 min readJan 25, 2022

https://github.com/Grimshire/choochoo.js

choochoo.js is a timing library that allows for certain functions to be executed within a defined timeframe, and all other queued functions to be ignored. This logic allows for lag-ridden or cpu intensive applications to work as intended by enabling a GUI to keep functioning in JS. Additionally, this logic is effectively a loop and could be used to drive games, especially games that require networking. I’m open to comments, gripes, and wicked cool ideas. The library is available for your use. I only ask that no one take credit for this original work.

choochoo.js works by creating a time interval, that allows for functions within that time interval, and ignores all that failed to arrive in time (hence the train/ticket/passenger metaphor). For example, say within the last second two events were fired 17 times each (a player advances his character sprite for example by holding down the forward and left keys). However, we only want to initiate what happened within say a 100th, a 10th, or half of a second and discard the rest, that way instead of 17 events, we can whittle them down to a few.

In a traditional queue algorithm, if latency occurred somewhere in our networking or in the processing of our program, our input from the user could be delayed while other events struggle to finish synchronizing. The resulting backup in our queue could either result in a lengthy execution of no longer desired inputs, or a sudden rush of executions, or both. choochoo.js gets rid of this problem for us by timestamping each input as they arrive and checking those timestamps when it's time to execute later.

--

--

Adam R Turner

Web developer who works daily with many technolgies. Has experience build a multitude of things all over the software spectrum. Really likes his cattledog Turbo