Skip to content

Streams

You can use async generators combined with signals to create streams completely controlled by the server.

@cloudstate
class YourClass {
@signal count = 0;
getCount() {
return this.count;
}
increment() {
return ++this.count;
}
async *countStream() {
const counter = useCloud<typeof YourClass>(this.id);
for await (getCount of counter.getCount) {
yield await getCount();
}
}
}
const counter = useCloud<typeof YourClass>("<instance-id>");
for await (const count of counter.countStream()) {
console.log(count);
}