Closed NicolasMahe closed 4 years ago
I updated API like below:
listenTask({ ...tasks }: Tasks): TaskStream
emitEvent(event: string, data: any): Promise<grpc.ServiceError|null>
listenTask() now returns a TaskStream. It has task, end events and cancel() method to cancel the stream.
let stream = listenTask({ ...tasks }: Tasks): TaskStream
stream.on('task', (task: Task) => {} )
stream.on('end', (err) => {} ) // err can be null when stream ended without an error
stream.cancel()
Please implement also the feedback from https://github.com/mesg-foundation/mesg-js/issues/40.
Does passing tasks to listenTask
call automatically the task when the service receive it?
Does listenTask
accept no argument and in this case, the developer has to use stream.on('task',...
?
What is grpc.ServiceError
? if it an error it doesn't need to be in the return type of the promise.
Please implement also the feedback from mesg-foundation/js-sdk#58.
Does passing tasks to
listenTask
call automatically the task when the service receive it? DoeslistenTask
accept no argument and in this case, the developer has to usestream.on('task',...
?What is
grpc.ServiceError
? if it an error it doesn't need to be in the return type of the promise.
Yes, we keep the previous behaviour as it's. Task handlers will be called when matching task execution is received.
It's for errors. It'll be passed as an argument to the catch() method when emitting event fails. In the next PRs, I'm planning to change grpc.ServiceError type to plain Error type. This way it'll not depend on the generated APIs. And, generated code for the web version is slightly different here (not grpc.ServiceError) so it's a good idea to change it as Error.
We decided to change public APIs again so this changes will not be reflected to master branch. However we’ll keep this implementation in another branch called generated-and-high-level-apis for future attention.
We need to create new type for the wrapper function to use. The generated type are not js developer friendly at all.
For example, https://github.com/mesg-foundation/mesg-js/pull/28/files#diff-ef7fcd1152991311bd36314bc5c76f17R24:
should not use TaskData from the generated pb files but use a JS friendly type like:
We can actually keep the interface from https://github.com/mesg-foundation/mesg-js/blob/master/src/client/service-client.ts