usim
v0.1.2
Published
minimal discrete time simulation in javascript
Downloads
1
Readme
usim
minimal discrete time simulation in javascript
##API
Get the uSim
class by var uSim = require("usim");
(node)
or define(["usim", ...], function (uSim, ...) { /*module code*/}
(AMD).
If needed, you can also just include it in <script src=".../usim.js"></script>
and use the global uSim
.
var usim = new uSim()
Creates new simulation timeline with initial time set to-Infinity
.usim.schedule(time, object)
Schedulesobject
to occur attime
.usim.time
The current simulation time.usim.peek()
Returns the object that is scheduled to earliest time ornull
. If the object's time is higher than current time, the current time is shifted accordingly.usim.peek(cb)
Same asusim.peek()
, but instead of returning the object, it calls the callback with the object ornull
as the only argument.usim.peekUntil(time)
Same asusim.peek()
, but if time of object if bigger thantime
,null
is returned instead and object stays in the schedule.usim.peekUntil(time, cb)
Same asusim.peek(cb)
, but if time of object if bigger thantime
,null
is passed instead and object stays in the schedule.usim.stream(cb)
Callscb
with all scheduled objects, as ifusim.peek(cb)
was called in loop while there are some scheduled objects.usim.streamUntil(time, cb)
Same asusim.stream(cb)
, but quits if time would be shifted pasttime
(IOW: streams all objects scheduled up totime
).usim.run()
Same asusim.stream(function (each) { each(usim) })
. IOW, treats all scheduled objects as functions and calls them, passing itself as the parameter.