grpc-dart
grpc-dart copied to clipboard
Use FutureOr instead of Future for ServiceBase
It will be more convinece to use the FutureOr from dart:async, since it makes more easy to implement simple method without adding the word async infront every one.
instead of:
class GreeterService extends GreeterServiceBase {
@override
Future<HelloReply> sayHello(ServiceCall call, HelloRequest request) async {
return HelloReply()..message = 'Hello, ${request.name}!';
}
}
do this:
class GreeterService extends GreeterServiceBase {
@override
FutureOr<HelloReply> sayHello(ServiceCall call, HelloRequest request) {
return HelloReply()..message = 'Hello, ${request.name}!';
}
}
FutureOr is hard to work with on the user's side. When you receive a FutureOr, you don't know whether you have to await or if you can use it directly. It's like using Object or dynamic, in that it tells you nothing about the type -- "it could be a future, or it could be a regular object" is not really helpful. It's much simpler to get a Future and await it every time, and that simplicity is probably worth typing out the async