Skip to content

Instantly share code, notes, and snippets.

@Clancey
Created May 1, 2020 06:44
Show Gist options
  • Save Clancey/824d3bcf85de10143de6195a3b878aff to your computer and use it in GitHub Desktop.
Save Clancey/824d3bcf85de10143de6195a3b878aff to your computer and use it in GitHub Desktop.
public class Testclass {
Action<bool> MyAction { get; set; }
Func<Task<bool>> MyAwaitedAction { get; set; }
public async Task AsyncTestMethod()
{
MyAction += (result) => {
Console.WriteLine(result);
};
MyAwaitedAction += () => {
return Task.FromResult(true);
};
MyAwaitedAction += () => {
return Task.FromResult(false);
};
//Wait until the action completes.
//Only the last subscribed function will return;
var result = await MyAwaitedAction();
MyAction.Invoke(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment