Packages
telegex
1.2.1
1.9.0-rc.0
1.8.0
1.7.0
1.6.0
1.5.0
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.3-dev
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
1.0.0-rc.10
1.0.0-rc.9
1.0.0-rc.8
1.0.0-rc.7
1.0.0-rc.6
1.0.0-rc.5
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.1.0-rc.11
0.1.0-rc.10
0.1.0-rc.9
0.1.0-rc.8
0.1.0-rc.7
0.1.0-rc.6
0.1.0-rc.5
0.1.0-rc.4
0.1.0-rc.3
0.1.0-rc.2
0.1.0-rc.1
0.0.4
0.0.3
0.0.2
0.0.1
A Telegram bot framework, with its client-side based on data and code generation, boasts unparalleled adaptation speed and correctness for new versions.
Current section
Files
Jump to
Current section
Files
lib/telegex/chain/handler.ex
defmodule Telegex.Chain.Handler do
@moduledoc false
# 以管道的形式调用多个 chain
def call(chains, update, context \\ %{}) when is_list(chains) and is_map(context) do
call_chain = fn chain, {_state, context} ->
case chain.call(update, context) do
{:ok, context} -> {:cont, {:ok, context}}
{:stop, context} -> {:halt, {:stop, context}}
{:done, context} -> {:halt, {:done, context}}
end
end
Enum.reduce_while(chains, {:init, context}, call_chain)
end
defmacro __using__(_) do
quote do
import unquote(__MODULE__), only: [pipeline: 1]
require unquote(__MODULE__)
end
end
defmacro pipeline(modules) do
quote do
def __chains__ do
unquote(modules)
end
@spec call(Telegex.Type.Update.t(), Telegex.Chain.context()) :: Telegex.Chain.result()
def call(update, context) do
unquote(__MODULE__).call(__MODULE__.__chains__(), update, context)
end
end
end
end