Running JS functions in background

I am trying to write a VU scenario where there are UDP datagrams being sent and received non stop between 2 moments. To do this, I need to have an infinite loop running in the background, which I close at the end of the default function(). If the function fails (VU is killed for any reason, i.e. an http timeout), the background function should stop as well.

Is there a way to do something like that?

Not in vanilla k6 with purely JS support, both because we don’t support raw UDP yet, and because we don’t have proper event loops (Global JS event loops in every VU · Issue #882 · k6io/k6 · GitHub).

Both of these should be achievable with an xk6 extension though.