-
Notifications
You must be signed in to change notification settings - Fork 3
/
invoke_echo.py
31 lines (25 loc) · 1.09 KB
/
invoke_echo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pathlib
from pycape import Cape
token_file = pathlib.Path(__file__).parent.absolute() / "user.token"
cape = Cape()
function_ref = cape.function("pycape-dev/echo")
token = cape.token(token_file)
if __name__ == "__main__":
cape.connect(function_ref, token)
result = cape.invoke("Hello Cape".encode())
print(f"The result is: {result.decode()}")
result = cape.invoke("Hello Gavin".encode())
print(f"The result is: {result.decode()}")
result = cape.invoke("Hello Hello".encode())
print(f"The result is: {result.decode()}")
cape.close()
# Note that instead you can use the connection_context
# context manager which will automatically close the
# connection and reset websocket connection's states.
with cape.function_context(function_ref, token):
result = cape.invoke("Hello Cape".encode())
print(f"The result is: {result.decode()}")
result = cape.invoke("Hello Gavin".encode())
print(f"The result is: {result.decode()}")
result = cape.invoke("Hello Hello".encode())
print(f"The result is: {result.decode()}")