elixir-circuits / circuits_i2c

Communicate over I2C from Elixir
Apache License 2.0
62 stars 12 forks source link

Defer loading the NIF until opening an I2C bus #138

Closed fhunleth closed 10 months ago

fhunleth commented 1 year ago

This change moves the NIF load from the time at which the module is loaded to the time when a I2C actually is used.

The primary motivation for doing this is to defer native code crashes from happening at load time to the time of first use. Load time is harder to debug and sometimes its not clear which NIF caused the crash.

The calls to apply get around some complexity with ignoring Dialyzer warnings. Dialyzer can't figure out that the recursive looking call actually invokes the NIF code.