#Calling a Module that's not availble !

4 messages · Page 1 of 1 (latest)

zealous river
#
 @impl true
  @doc """
  Make a quick network scan , and push it to the front !
  """
  @spec handle_cast({:push_wifi_networks}, State.t()) :: {:noreply, State.t()}
  def handle_cast({:push_wifi_networks}, state) do
    # TO DO  should work on making the state updatable !

        Logger.info("scan")
        networks = VintageNetWifi.quick_scan(4000)

        :ok = Ps.broadcast(MainPubSub, "main:0", {:push_wifi_networks, networks})
        {:noreply, state}
    end

hi guys , here i have the VintageNetWifi , the module will be availble till the entire Nerves Runtime is running -i.e running the app in the Target - , but i need to keep the code even in the case of not having the module available at the moment !

in the mix.exs , i didnt define that dep , but it's defined in one of this nerves systems !

candid zinc
#

If I understand right you can do something like:

if Code.ensure_loaded?(MyModuleName) do
   # do your stuff here
end```
#

Usually I've seen it used for conditionally defining modules or things at compile time. So maybe it won't work for your situation

zealous river
#

ooh thanks , i have no idea why i didnt think about it ! ❤️