-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Websocket support in chains (entrypoint only).
- Loading branch information
1 parent
0c1d882
commit 5eeca91
Showing
12 changed files
with
354 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import fastapi | ||
|
||
import truss_chains as chains | ||
|
||
|
||
class Dependency(chains.ChainletBase): | ||
async def run_remote(self, name: str) -> str: | ||
msg = f"Hello from dependency, {name}." | ||
print(msg) | ||
return msg | ||
|
||
|
||
@chains.mark_entrypoint # ("My Chain Name") | ||
class Head(chains.ChainletBase): | ||
def __init__(self, dependency=chains.depends(Dependency)): | ||
self._dependency = dependency | ||
|
||
async def run_remote(self, websocket: chains.WebSocketProtocol) -> None: | ||
try: | ||
while True: | ||
text = await websocket.receive_text() | ||
if text == "dep": | ||
result = await self._dependency.run_remote("Head") | ||
else: | ||
result = f"You said: {text}." | ||
await websocket.send_text(result) | ||
except fastapi.WebSocketDisconnect: | ||
print("Disconnected.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.