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
if (msg.payload==='Hello World') break; // Exit loop to close
86
+
}
84
87
85
88
awaitchannel.close();
86
89
```
@@ -91,3 +94,13 @@ Remember to close the mesh connection when your application exits.
91
94
```typescript
92
95
awaitmesh.close();
93
96
```
97
+
98
+
### 6. Async Iterators (Backpressure)
99
+
Mesh supports Async Iterators (`for await...of`) for consuming messages. This is the **recommended** way to read from a channel as it automatically handles backpressure: the sender will be slowed down if your processing loop is slower than the incoming data rate.
100
+
101
+
```typescript
102
+
forawait (const msg ofchannel) {
103
+
awaitprocessMessage(msg);
104
+
// The next message is only requested after this line completes
if msg.payload =="Hello World": break# Exit loop to close
93
95
94
96
await channel.close()
95
97
```
98
+
99
+
### 5. Async Iterators (Backpressure)
100
+
Mesh supports Async Iterators (`async for ... in`) for consuming messages. This is the **recommended** way to read from a channel as it automatically handles backpressure.
101
+
102
+
```python
103
+
asyncfor msg in channel:
104
+
await process_message(msg)
105
+
# The next message is consumed only after the loop body finishes
0 commit comments