{"id":13514976,"url":"https://github.com/pouriya/posthaste","last_synced_at":"2025-03-31T04:36:08.741Z","repository":{"id":113706093,"uuid":"133995385","full_name":"pouriya/posthaste","owner":"pouriya","description":"Blazingly fast Erlang/Elixir hooking library.","archived":true,"fork":false,"pushed_at":"2019-08-25T17:53:21.000Z","size":1357,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-01T18:38:08.525Z","etag":null,"topics":["elixir","elixir-library","erlang","erlang-library","hook","hook-manager","hooking"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pouriya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-05-18T19:21:37.000Z","updated_at":"2024-04-25T10:45:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"ed916c0c-3b94-4877-9fbd-bfdccc62d532","html_url":"https://github.com/pouriya/posthaste","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pouriya%2Fposthaste","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pouriya%2Fposthaste/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pouriya%2Fposthaste/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pouriya%2Fposthaste/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pouriya","download_url":"https://codeload.github.com/pouriya/posthaste/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246418658,"owners_count":20773934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","elixir-library","erlang","erlang-library","hook","hook-manager","hooking"],"created_at":"2024-08-01T05:01:04.793Z","updated_at":"2025-03-31T04:36:08.081Z","avatar_url":"https://github.com/pouriya.png","language":"Erlang","funding_links":[],"categories":["Erlang"],"sub_categories":[],"readme":"![posthaste travis test status](https://travis-ci.org/Pouriya-Jahanbakhsh/posthaste.png?branch=master)\n\n# posthaste\nAn Erlang/Elixir [hooking](https://en.wikipedia.org/wiki/Hooking) library.  \n\n# When to use Posthaste ?\nWhen you want to lookup callbacks of hooks (especially with large numbers of processes at the same time), Posthaste is about **3-5 times faster** than Erlang ETS. But in add/delete operations it's too slow (compared with ETS). Then if you have more lookup operation than add/delete operations, use Posthaste.\n\n# How to use?\nIn Posthaste, each **hook** must be an Erlang `atom`.  \n```erlang\n-type hook() :: atom().\n```\nEach **hook** has one or more **key**.  \n```erlang\n-type key() :: atom() | binary() | number() | list() | tuple().\n```\nFinally each **key** has its own **handlers**. **handlers** is a list which may contain one or more **handler**. Each **handler** contains **priority** which is non negative `integer` and **module** and **function** which are `atom`s.  \n```erlang\n-type handlers() :: [] | [handlers()].\n-type  handlers() :: {priority(), module(), func()}.\n-type   priority() :: non_neg_integer().\n-type   func() :: atom().\n```\nPosthaste maps each **key** to its **handlers** for each **hook**:\n```erlang\n1\u003e Hooks = my_hooks.\nmy_hooks\n\n%% Starting hook server process:\n2\u003e posthaste:start_link(Hooks).\n{ok,\u003c0.97.0\u003e}\n\n3\u003e Hook1 = foo.\nfoo\n\n4\u003e Key1 = bar.\nbar\n\n%% Adding a hook with priority 10, module 'module' and function 'function':\n5\u003e posthaste:add(Hooks, Hook1, Key1, module, function, 10).\nok\n\n%% Getting handlers of Key1 for Hook1:\n6\u003e posthaste:handlers(Hooks, Hook1, Key1).\n[{10, module, function}]\n\n7\u003e posthaste:add(Hooks, Hook1, Key1, module, function, 10).\nok\n8\u003e posthaste:add(Hooks, Hook1, Key1, module2, function2, 20).\nok\n9\u003e posthaste:add(Hooks, Hook1, Key1, module2, function2, 15).\nok\n\n10\u003e posthaste:handlers(Hooks, Hook1, Key1).                  \n[{10, module, function},\n {10, module, function},\n {15, module2, function2},\n {20, module2, function2}]\n\n11\u003e Key2 = baz.                                               \nbaz\n12\u003e posthaste:add(Hooks, Hook1, Key2, mod, func, 100).        \nok\n\n13\u003e posthaste:handlers(Hooks, Hook1, Key2).          \n[{100,{mod,func}}]\n\n14\u003e posthaste:handlers(Hooks, Hook1, Key1).\n[{10, module, function},\n {10, module, function},\n {15, module2, function2},\n {20, module2, function2}]\n\n%% New hook:\n15\u003e Hook2 = qux.                                      \nqux\n16\u003e posthaste:add(Hooks, Hook2, Key1, m, f, 1).        \nok\n17\u003e posthaste:handlers(Hooks, Hook2, Key1).   \n[{1, m, f}]\n\n%% Deleting a callback:\n18\u003e posthaste:delete(Hooks, Hook1, Key1, module2, function2, 15).\nok\n19\u003e posthaste:callbacks(Hooks, Hook1, Key1).                     \n[{10, module,function},\n {10, module,function},\n {20, module2,function2}]\n```\n\n# What is going on? (under the hood)\nLet's run above code snippet again:  \n```erlang\n1\u003e Hooks = my_hooks.        \nmy_hooks\n2\u003e posthaste:start_link(Hooks).\n{ok,\u003c0.97.0\u003e}\n3\u003e Hook1 = foo.\nfoo\n4\u003e Key1 = bar.\nbar\n5\u003e posthaste:add(Hooks, Hook1, Key1, module, function, 10).\nok\n\n6\u003e Hooks:Hook1(Key1).\n[{10, module, function}]\n\n7\u003e my_hooks:foo(bar).\n[{10, module, function}]\n```\nActually each Posthaste server process creates new Erlang module and adds every **hook** as an Erlang function to it. **key** is an argument of **hook** function and finally **callbacks** are in function body.\n\n### Contributing\nI love pull requests from everyone. But it's good to explain idea, feautre or bug in issues before.\n\n### Author\n**`pouriya.jahanbakhsh@gmail.com`**\n\n### License\n**`BSD 3-Clause`**\n\n### Hex version\n[**`18.5.19`**](https://hex.pm/packages/posthaste)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpouriya%2Fposthaste","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpouriya%2Fposthaste","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpouriya%2Fposthaste/lists"}