You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// To stop receiving, you can close the channel from within handler or check explicitly
79
79
if (msg.payload==='Hello World') {
@@ -92,11 +92,11 @@ await mesh.close();
92
92
```
93
93
94
94
### 6. Callback-based Backpressure
95
-
Mesh supports `onData(handler)` for consumers who prefer callbacks but need backpressure. The method returns `void` (fire-and-forget), and the processing loop runs in the background.
95
+
Mesh supports `onData(handler)` for consumers who prefer callbacks but need backpressure. The method returns a `Promise` that resolves when the stream is closed, allowing you to `await`the entire processing session.
96
96
97
97
```typescript
98
98
```typescript
99
-
channel.onData(async (msg) => {
99
+
await channel.onData(async (msg) => {
100
100
await processMessage(msg);
101
101
// The next message is only requested after this line completes
Mesh supports `on_data(handler)` for consuming messages with backpressure. The method returns `None` (fire-and-forget), and the processing loop runs in the background using `asyncio.create_task`.
97
+
Mesh supports `on_data(handler)` for consuming messages with backpressure. The method returns an `Awaitable` that resolves when the stream is closed, allowing you to `await` the entire processing session.
98
98
99
99
```python
100
100
asyncdefhandler(msg):
101
101
await process_message(msg)
102
102
# The next message is consumed only after this function returns
0 commit comments