What is a task equivalent to Promise.then ()?

With the addition of async / await to TypeScript using Promise (s), it might look syntactically close to the Task (s).

Example:

Promise (TS)

public aync myAsyncFun(): Promise<T> { let value: T = await ... return value; } 

Task (C #)

 public aync Task<T> MyAsyncFun() { T value = await ... return value; } 

I was wondering, on the contrary, there was an equivalent .then () for Task (s).

Example:

Promise (TS)

 Promise<T> promise = ... promise.then((result: T) => ...do something...); 
+9
source share
2 answers

I used ContinueWith which can work if you have one or more tasks running.

example:

 public async Task<T> MyAsyncFun() { T value = await ... return value; } MyAsyncFun().ContinueWith(... 

https://msdn.microsoft.com/en-us/library/dd270696(v=vs.110).aspx

+7
source

You can use the wait method of an asynchronous task.

  public void Remove(int[] ids) { var entities = EntitySet.Where(x => x.IsActive && ids.Contains(x.Id)); var task = entities.ForEachAsync(x => { x.IsActive = false; Context.Entry(x).State = EntityState.Modified; }); task.Wait(); Context.SaveChanges(); } 
-1
source

Source: https://habr.com/ru/post/1261352/


All Articles