Skip to content

In WithParsed () method, I cann't await async in lambda . #332

@moh-hassan

Description

@moh-hassan

The call await new Command(x).Execute() which is called from within await async lambda, does not wait for the task completion and the next line is executed immediately.

The next code isn't working fine:

   static void Main(string[] args)
    {
	  RunOptions(args);
    }

   static void RunOptions(string[] args)
    {
	var parser= new Parser();
      var result = parser.ParseArguments<Options>(args);
         //note async x in lambda
        result.WithParsed(async x => {               
            await new Command(x).Execute();
        });			 
  }

I think it is expected because it's against the principle use async all the way up

How to use async/await in result.WithParsed
I want to re-write the code to use asyn Main() in C#7.1

  static async Task Main(string[] args)
    {
	await  RunOptions(args);
    }

   static async Task RunOptions(string[] args)
    {
        //rewrite the code using result.WithParsed(...)
       // or WithParsed don't support async/await
   }

I find this example for MapResult , but i need to use .WithParsed`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions