Skip to content

Instantly share code, notes, and snippets.

@ammeep
Last active September 15, 2015 15:10
Show Gist options
  • Save ammeep/7de072ce3bc808c2d25e to your computer and use it in GitHub Desktop.
Save ammeep/7de072ce3bc808c2d25e to your computer and use it in GitHub Desktop.
A C# example of how we might use locks inside GitHub Desktop
public class LockExample
{
private IRepository repository;
public LockExample(IRepository repository)
{
this.repository = repository;
}
public IObservable<Unit> Fetch()
{
// execute a git fetch
}
public IObservable<Unit> FindMergeBase(Sha first, Sha second)
{
// calculate the merge base between two sha's
}
public IObservable<Unit> Commit()
{
// create a commit
}
public void DoWork(Sha first, Sha second)
{
repository.WithConcurrentConnection(Fetch)
.Subscribe();
repository.WithConcurrentConnection(FindMergeBase(first, second))
.Subscribe();
repository.WithExclusiveConnection(Commit)
.Subscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment