Skip to content

Instantly share code, notes, and snippets.

@lostmsu
Created October 1, 2016 23:31
Show Gist options
  • Save lostmsu/90b9a1e48ed002b6b4f574fb45799ad0 to your computer and use it in GitHub Desktop.
Save lostmsu/90b9a1e48ed002b6b4f574fb45799ad0 to your computer and use it in GitHub Desktop.
The problem interface for the Responsive Autosave Problem (lookup the post on blogger)
// Instances of this class are not thread-safe
// E.g. only one thread can safely call Save and DisposeAsync
//
interface IAsyncSaveService {
// this function schedules save operation to be performed
// implementers of this interface must ensure, that only one save operation can run at the same time
// saveOperation is considered completed when the task it returned is completed
void Save(Func<Task> saveOperation);
// after a call to this function no calls to Save are allowed and must throw ObjectDisposedException
// this function can be called any number of times
// awaiting the task, returned by this function must ensure, that the last save operation added by Save() is completed
Task DisposeAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment