Documentation ¶
Overview ¶
Package eventloop implements an event loop to be used thought js and it's subpackages
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventLoop ¶
type EventLoop struct {
// contains filtered or unexported fields
}
EventLoop implements an event with handling of unhandled rejected promises.
A specific thing about this event loop is that it will wait to return not only until the queue is empty but until nothing is registered that it will run in the future. This is in contrast with more common behaviours where it only returns on a specific event/action or when the loop is empty. This is required as in k6 iterations (for which event loop will be primary used) are supposed to be independent and any work started in them needs to finish, but also they need to end when all the instructions are done. Additionally because of this on any error while the event loop will exit it's required to wait on the event loop to be empty before the execution can continue.
func New ¶
New returns a new event loop with a few helpers attached to it: - adding setTimeout javascript implementation - reporting (and aborting on) unhandled promise rejections
func (*EventLoop) RegisterCallback ¶
RegisterCallback register that a callback will be invoked on the loop, preventing it from returning/finishing. The returned function, upon invocation, will queue its argument and wakeup the loop if needed. If the eventLoop has since stopped, it will not be executed. This function *must* be called from within running on the event loop, but its result can be called from anywhere.
func (*EventLoop) Start ¶
Start will run the event loop until it's empty and there are no uninvoked registered callbacks or a queued function returns an error. The provided firstCallback will be the first thing executed. After Start returns the event loop can be reused as long as waitOnRegistered is called.
func (*EventLoop) WaitOnRegistered ¶
func (e *EventLoop) WaitOnRegistered()
WaitOnRegistered waits on all registered callbacks so we know nothing is still doing work.