zigler v0.2.0 Zigler.Code.LongRunning View Source
Generates code for long-running nifs.
long-running functions require several parts to get right.
a zig struct needs to be that holds arguments relvant to the long-running nif, these arguments need to be cleaned up in a sane fashion once the nif has completed running. This struct is going to be argetric on the nif arguments, and will be packed into a BEAM resource.
a
packer
function which takes the beam arguments and shoves them into a zig struct to be stored in a BEAM resource, then launches the function, returning the resource.a
launcher
function which runs thepacker
wrapping the errors from the launch function. The launch function must be a nif function, as it will be called from the BEAM.a
harness
function which is passed the resource struct, and is responsible for updating the resource, sending back a "finished" message to parent context. The harness function will be responsible for wrapping the declared nif function.a
fetching
function which is passed the resource struct, and marshals it back into BEAM terms, returning the result. This function must be a nif function, as it will be called from the BEAM.a
cleanup
function which is responsible for cleaning up the resource object once the thread has completed its task.