Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async support in WS #134

Merged
merged 7 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update docs
  • Loading branch information
sansyrox committed Dec 20, 2021
commit 6a3c22e21a89c758684af6e336c9c215e49659ef
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ app.start(port=5000)

## Features
- Under active development!
- Written in Russt, btw xD
- Written in Rust, btw xD
- A multithreaded Runtime
- Extensible
- A simple API
Expand Down
38 changes: 37 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ app = Robyn(__file__)
websocket = WS(app, "/web_socket")
```

Now, you can define 3 methods for every web_socket for their lifecycle, they are as follows:
Now, you can define 3 methods for every web_socket for their life cycle, they are as follows:

```python3
@websocket.on("message")
Expand Down Expand Up @@ -196,6 +196,42 @@ The three methods:

To see a complete service in action, you can go to the folder [../integration_tests/base_routes.py](../integration_tests/base_routes.py)

### Update(20/12/21)

Async functions are supported in Web Sockets now!

Async functions are executed out of order for web sockets. i.e. the order of response is not guaranteed. This is done to achieve a non blocking concurrent effect.

A blocking async web socket is in plans for the future.

### Usage

```python3
@websocket.on("message")
async def connect():
global i
i+=1
if i==0:
return "Whaaat??"
elif i==1:
return "Whooo??"
elif i==2:
return "*chika* *chika* Slim Shady."
elif i==3:
i= -1
return ""

@websocket.on("close")
async def close():
return "Goodbye world, from ws"

@websocket.on("connect")
async def message():
return "Hello world, from ws"

```


## MutliCore Scaling

To run Robyn across multiple cores, you can use the following command:
Expand Down