11# system imports
22from collections import OrderedDict
3- from typing import Callable , Any
3+ from typing import Callable , Dict , Any
44
55# web imports
66from flask_executor import Executor
@@ -74,7 +74,7 @@ def register_command(
7474 self ,
7575 endpoint : str ,
7676 command_name : str ,
77- callback_fn : Callable [[Future ], Any ] = None ,
77+ callback_fn : Callable [[Dict , Future ], Any ] = None ,
7878 ) -> None :
7979 """
8080 Function to map a shell command to an endpoint.
@@ -89,17 +89,19 @@ def register_command(
8989 For example,
9090 if you pass ``{ "args": ["Hello", "World"] }``
9191 in POST request, it gets converted to ``echo Hello World``.\n
92- callback_fn (func ):
92+ callback_fn (Callable[[Dict, Future], Any] ):
9393 - An optional function that is invoked when a requested process
9494 to this endpoint completes execution.
9595 - This is added as a
9696 ``concurrent.Future.add_done_callback(fn=callback_fn)``
97- - A same callback function may be used for multiple commands.
97+ - The same callback function may be used for multiple commands.
98+ - if request JSON contains a `callback_context` attr, it will be passed
99+ as the first argument to this function.
98100
99101 Examples::
100102
101- def my_callback_fn(future) :
102- print(future.result())
103+ def my_callback_fn(context: dict, future: Future) -> None :
104+ print(future.result(), context )
103105
104106 shell2http.register_command(endpoint="echo", command_name="echo")
105107 shell2http.register_command(
@@ -108,7 +110,7 @@ def my_callback_fn(future):
108110 callback_fn=my_callback_fn
109111 )
110112 """
111- uri = self .__construct_route (endpoint )
113+ uri : str = self .__construct_route (endpoint )
112114 # make sure the given endpoint is not already registered
113115 cmd_already_exists = self .__commands .get (uri )
114116 if cmd_already_exists :
0 commit comments