fluttercommunity / rx_command

RxCommand - Reactive event handler wrapper class inspired by ReactiveUI. Maintainer @escamoteur
https://pub.dev/packages/rx_command
MIT License
134 stars 19 forks source link

RxCommands with asynchronous handlers should be await able #16

Closed lemoony closed 5 years ago

lemoony commented 5 years ago

Hey, first of all: Thank you for this library, it's already immensely useful.

I think it would great if RxCommands with asynchronous handlers are awaitable. This way, one can compose more complex RxCommands from simpler one. E.g.:

RxCommand<User, void> updateUser = RxCommand.createAsyncNoResult<User>({ // ... });
RxCommand<void, void> synchronize = RxCommand.createAsyncNoParamNoResult({ // ... });

RxCommand<User, void> doStuff =  RxCommand.createAsyncNoResult(() {
      await updateUser(...);
      await synchronize();
});
anaisbetts commented 5 years ago

Good idea! I've added a sketch of this feature in #18

lemoony commented 5 years ago

Great, thanks!

What do you think about returning the next property also from the call function?

Future<TResult> call([TParam param]) => execute(param);

Otherwise, we have to first call execute() and then await on the next property instead of just await on the execute method.

Not sure however if this may introduce some unwanted side effects.