hasanaktasTR
hasanaktasTR
TtRPC
Created by hasanaktasTR on 10/14/2024 in #❓-help
Help for subscription with redis
@BeBoRE I had looked at the example in the document but it had not occurred to me that the on function in node:events could work with redis. I have never used eventemitter before. Do you think the following setup is correct?
const listSubscription= profileProcedure
.input(
z.object({
matchId: z.string(),
}),
)
.subscription(async function* ({ signal, input, ctx }) {
console.log("connection opened");
await ctx.eventSub.subscribe(input.matchId);

try {
for await (const [_, message] of on(ctx.eventSub, "message", {
signal: signal,
})) {
const post = JSON.parse(message);
yield post;
}
} finally {
console.log("connection closed");
ctx.eventSub.unsubscribe(input.matchId);
}
})
const listSubscription= profileProcedure
.input(
z.object({
matchId: z.string(),
}),
)
.subscription(async function* ({ signal, input, ctx }) {
console.log("connection opened");
await ctx.eventSub.subscribe(input.matchId);

try {
for await (const [_, message] of on(ctx.eventSub, "message", {
signal: signal,
})) {
const post = JSON.parse(message);
yield post;
}
} finally {
console.log("connection closed");
ctx.eventSub.unsubscribe(input.matchId);
}
})
12 replies