Skip to content

Instantly share code, notes, and snippets.

@scionwest
Created January 4, 2015 03:39
Show Gist options
  • Save scionwest/8f919253b9a3993b9f6c to your computer and use it in GitHub Desktop.
Save scionwest/8f919253b9a3993b9f6c to your computer and use it in GitHub Desktop.
private List<Func<Task>> ShutdownCallbacks = new List<Func<Task>>();
public void RegisterShutdownCallback(Func<Task> callback)
{
this.ShutdownCallbacks.Add(callback);
}
public async Task Shutdown()
{
var callbackTasks = new List<Task>();
foreach(var callback in this.ShutdownCallbacks)
{
callbackTasks.Add(callback());
}
await Task.WhenAll(callbackTasks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment