bilal-fazlani / commanddotnet

A modern framework for building modern CLI apps
https://commanddotnet.bilal-fazlani.com
MIT License
560 stars 32 forks source link

Dispose is called before async command finishes executing #488

Closed Sibusten closed 7 months ago

Sibusten commented 8 months ago

The implementation of AppRunner.OnRunCompleted does not await next, causing the event to be fired before the async command finishes executing. This causes Dispose to be invoked early.

private Task<int> OnRunCompleted(CommandContext context, ExecutionDelegate next)
{
    var result = next(context);
    context.AppConfig.OnRunCompleted?.Invoke(new OnRunCompletedEventArgs(context));
    return result;
}
drewburlingame commented 8 months ago

Thanks for filing this @Sibusten. I'll look into it this week. If you need this immediately, I'll happily accept a PR with tests.

drewburlingame commented 7 months ago

this is resolved with https://www.nuget.org/packages/CommandDotNet/7.0.3. Thanks for reporting and helping with the tests.