nomasystems/nhooks

Erlang hooks library

ErlangPython
This is stars and forks stats for /nomasystems/nhooks repository. As of 01 May, 2024 this repository has 12 stars and 0 forks.

nhooks Erlang hooks application. It allows adding tasks dynamically to predefined hooks. Status Prerequisites Configuration In your rebar.config file, add the dependency: {deps, [ {nhooks, {git, "[email protected]:nomasystems/nhooks.git", {branch, "main"}}} ]}. Usage example Assuming there is a module named test_app that has one hook named init and another named terminate: -module(test_app). %%% EXTERNAL EXPORTS -export([init/1, terminate/1]). %%% NHOOKS EXPORTS -export([hooks/0]). %%%----------------------------------------------------------------------------- %%% EXTERNAL EXPORTS %%%----------------------------------------------------------------------------- init(Term) -> nhooks:do(?MODULE, init, [Term]). terminate(Term) -> nhooks:do(?MODULE, terminate, [Term]). hooks() -> [ init, terminate ]. You can register tasks to the defined hooks: %%% Registering tasks in both hooks ok = nhooks:register_task(test_app, init, fun(Term) -> do_something(Term) end). ok = nhooks:register_task(test_app, terminate, fun(Term) -> do_something_else(Term) end). From now on when test_app executes the init and terminate hooks the registered tasks will be executed. You can also register multiple tasks to any defined hook: %%% Registering multiple tasks to same hook ok = nhooks:register_task(test_app, init, fun(Term) -> do_something(Term) end). ok = nhooks:register_task(test_app, init, fun(Term) -> do_something_else(Term) end). And all will be executed when test_app executes the init hook. If you want to stop the subsequent tasks from executing, you can return stop or {stop, Data} from any task. For example: %%% Stopping subsequent tasks in the same hook ok = nhooks:register_task(test_app, init, fun(Term) -> do_something(Term), {stop, {some, data}} end). ok = nhooks:register_task(test_app, init, fun(Term) -> do_something_else(Term) end). In this case, the second task won't be executed and the call to nhooks:do/3 will return {stopped, {some, data}}. Support Any doubt or suggestion? Please check out our issue tracker.
Read on GithubGithub Stats Page
repotechsstarsweeklyforksweekly
endeve/thornadoFortranTeXPython120110
eddwebster/football_analyticsJupyter NotebookPython1.3k02090
ben1234560/AiLearning-Theory-ApplyingJupyter NotebookPython2.6k03960
binsec/binsecOCamlPythonC2820300
samuelcolvin/pydantic-corePythonRustOther1.1k01290
lightrush/framework-laptop-formulaSaltStackPythonShell95070
scalapb/ScalaPBScalaHTMLJavaScript1.3k+1276+1
t4sk/defi-by-exampleSolidityJavaScriptPython53102200
IntelRealSense/realsense-rosPythonC++CMake2.2k01.6k0
pixie-io/pixieC++GoTypeScript4.9k03830