Skip to content

Commit 7003823

Browse files
committed
Fix gRPC streams
1 parent ea55be9 commit 7003823

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

components/server/src/api/server.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,25 @@ export class API {
255255
});
256256
}
257257

258-
let subjectId: SubjectId | undefined = undefined;
258+
// Because we can't await before returning that generator, we await inside the generator, and create child contexts with that SubjectId
259259
return wrapAsyncGenerator(
260260
(async function* () {
261261
try {
262-
subjectId = await auth();
263-
264-
const generator = await apply<AsyncGenerator<any>>();
265-
for await (const item of generator) {
266-
yield item;
262+
const subjectId = await auth();
263+
const generator = await runWithSubjectId(subjectId, () => apply<AsyncGenerator<any>>());
264+
while (true) {
265+
const { value, done } = await runWithSubjectId(subjectId, () => generator.next());
266+
if (done) {
267+
break;
268+
}
269+
yield value;
267270
}
268271
done();
269272
} catch (e) {
270273
handleError(e);
271274
}
272275
})(),
273-
(f) => runWithSubjectId(subjectId, f),
276+
(f) => withRequestContext(f),
274277
);
275278
};
276279
},

0 commit comments

Comments
 (0)