zigler v0.3.0 Zigler.Code.LongRunning View Source

Generates code for long-running nifs.

long-running functions require several parts to get right.

  1. 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.

  2. 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.

  3. a launcher function which runs the packer wrapping the errors from the launch function. The launch function must be a nif function, as it will be called from the BEAM.

  4. 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.

  5. 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.

  6. a cleanup function which is responsible for cleaning up the resource object once the thread has completed its task.

Link to this section Summary

Link to this section Functions