Packages
Event-Hub is a Gleam library that provides simple hubs with publishers and subscribers for event-driven observers. It supports asynchronous message handling and event notifications, decoupling components efficiently. It works on Erlang and JavaScript.
Current section
Files
Jump to
Current section
Files
src/event_hub@filtered.erl
-module(event_hub@filtered).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/1, notify/3, subscribe/3, new2/1, notify2/4, subscribe2/4, new3/1, notify3/5, subscribe3/5, new4/1, notify4/6, subscribe4/6]).
-export_type([hub/2, hub2/3, hub3/4, hub4/5]).
-opaque hub(FZF, FZG) :: {hub, event_hub:hub({list(FZG), FZF})}.
-opaque hub2(FZH, FZI, FZJ) :: {hub2, hub({list(FZJ), FZH}, FZI)}.
-opaque hub3(FZK, FZL, FZM, FZN) :: {hub3, hub2({list(FZN), FZK}, FZL, FZM)}.
-opaque hub4(FZO, FZP, FZQ, FZR, FZS) :: {hub4,
hub3({list(FZS), FZO}, FZP, FZQ, FZR)}.
-spec new(fun((hub(any(), any())) -> GAA)) -> GAA.
new(Context) ->
event_hub:new(
fun(Hub) ->
Hub@1 = {hub, Hub},
Context(Hub@1)
end
).
-spec notify(hub(GAB, GAC), list(GAC), GAB) -> nil.
notify(Hub, Topics, Value) ->
event_hub:notify(erlang:element(2, Hub), {Topics, Value}).
-spec subscribe(hub(GAG, GAH), list(GAH), fun((GAG) -> nil)) -> fun(() -> nil).
subscribe(Hub, Topics, Callback) ->
Topics@1 = gleam@set:from_list(Topics),
event_hub:subscribe(
erlang:element(2, Hub),
fun(_use0) ->
{Event_topics, Event_value} = _use0,
case gleam@list:any(
Event_topics,
fun(Topic) -> gleam@set:contains(Topics@1, Topic) end
) of
true ->
Callback(Event_value);
false ->
nil
end
end
).
-spec new2(fun((hub2(any(), any(), any())) -> GAS)) -> GAS.
new2(Context) ->
new(
fun(Hub) ->
Hub@1 = {hub2, Hub},
Context(Hub@1)
end
).
-spec notify2(hub2(GAT, GAU, GAV), list(GAU), list(GAV), GAT) -> nil.
notify2(Hub, Topics1, Topics2, Value) ->
notify(erlang:element(2, Hub), Topics1, {Topics2, Value}).
-spec subscribe2(hub2(GBB, GBC, GBD), list(GBC), list(GBD), fun((GBB) -> nil)) -> fun(() -> nil).
subscribe2(Hub, Topics1, Topics2, Callback) ->
Topics = gleam@set:from_list(Topics2),
subscribe(
erlang:element(2, Hub),
Topics1,
fun(_use0) ->
{Event_topics, Event_value} = _use0,
case gleam@list:any(
Event_topics,
fun(Topic) -> gleam@set:contains(Topics, Topic) end
) of
true ->
Callback(Event_value);
false ->
nil
end
end
).
-spec new3(fun((hub3(any(), any(), any(), any())) -> GBS)) -> GBS.
new3(Context) ->
new2(
fun(Hub) ->
Hub@1 = {hub3, Hub},
Context(Hub@1)
end
).
-spec notify3(hub3(GBT, GBU, GBV, GBW), list(GBU), list(GBV), list(GBW), GBT) -> nil.
notify3(Hub, Topics1, Topics2, Topics3, Value) ->
notify2(erlang:element(2, Hub), Topics1, Topics2, {Topics3, Value}).
-spec subscribe3(
hub3(GCE, GCF, GCG, GCH),
list(GCF),
list(GCG),
list(GCH),
fun((GCE) -> nil)
) -> fun(() -> nil).
subscribe3(Hub, Topics1, Topics2, Topics3, Callback) ->
Topics = gleam@set:from_list(Topics3),
subscribe2(
erlang:element(2, Hub),
Topics1,
Topics2,
fun(_use0) ->
{Event_topics, Event_value} = _use0,
case gleam@list:any(
Event_topics,
fun(Topic) -> gleam@set:contains(Topics, Topic) end
) of
true ->
Callback(Event_value);
false ->
nil
end
end
).
-spec new4(fun((hub4(any(), any(), any(), any(), any())) -> GDA)) -> GDA.
new4(Context) ->
new3(
fun(Hub) ->
Hub@1 = {hub4, Hub},
Context(Hub@1)
end
).
-spec notify4(
hub4(GDB, GDC, GDD, GDE, GDF),
list(GDC),
list(GDD),
list(GDE),
list(GDF),
GDB
) -> nil.
notify4(Hub, Topics1, Topics2, Topics3, Topics4, Value) ->
notify3(erlang:element(2, Hub), Topics1, Topics2, Topics3, {Topics4, Value}).
-spec subscribe4(
hub4(GDP, GDQ, GDR, GDS, GDT),
list(GDQ),
list(GDR),
list(GDS),
list(GDT),
fun((GDP) -> nil)
) -> fun(() -> nil).
subscribe4(Hub, Topics1, Topics2, Topics3, Topics4, Callback) ->
Topics = gleam@set:from_list(Topics4),
subscribe3(
erlang:element(2, Hub),
Topics1,
Topics2,
Topics3,
fun(_use0) ->
{Event_topics, Event_value} = _use0,
case gleam@list:any(
Event_topics,
fun(Topic) -> gleam@set:contains(Topics, Topic) end
) of
true ->
Callback(Event_value);
false ->
nil
end
end
).