Skip to content

Commit

Permalink
docs(core): Update example for WorkerMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jan 13, 2021
1 parent 51af5a0 commit 7af51d0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/core/src/worker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @example
* ```TypeScript
* export class ReindexMessage extends WorkerMessage<{ ctx: RequestContext }, boolean> {
* export class ReindexMessage extends WorkerMessage<{ ctx: SerializedRequestContext }, boolean> {
* static readonly pattern = 'Reindex';
* }
*
Expand All @@ -15,15 +15,21 @@
* constructor(private workerService: WorkerService) {}
*
* reindex(ctx: RequestContext): Observable<boolean>> {
* return this.workerService.send(new ReindexMessage({ ctx }))
* // If you need to send the RequestContext object to the worker,
* // be sure to send a serialized version to avoid errors.
* const serializedCtx = ctx.serialize();
* return this.workerService.send(new ReindexMessage({ ctx: serializedCtx }))
* }
* }
*
* // in a microservice Controller on the worker process
* class MyController {
*
* \@MessagePattern(ReindexMessage.pattern)
* reindex({ ctx: rawContext }: ReindexMessage['data']): Observable<ReindexMessage['response']> {
* reindex({ ctx: serializedCtx }: ReindexMessage['data']): Observable<ReindexMessage['response']> {
* // Convert the SerializedRequestContext back into a regular
* // RequestContext object
* const ctx = RequestContext.deserialize(serializedCtx);
* // ... some long-running workload
* }
* }
Expand Down

0 comments on commit 7af51d0

Please sign in to comment.