Skip to content

Instantly share code, notes, and snippets.

@2garryn
Created June 5, 2020 15:24
Show Gist options
  • Save 2garryn/6d11bf573781edb559f57683a0200808 to your computer and use it in GitHub Desktop.
Save 2garryn/6d11bf573781edb559f57683a0200808 to your computer and use it in GitHub Desktop.
class NonBlockingReplicator: INonBlockingReplicator
{
public event EventHandler Replicated;
private readonly IHttpReplicator _httpReplicator;
public NonBlockingReplicator(IHttpReplicator httpReplicator) => _httpReplicator = httpReplicator;
public void Replicate(Guid id, string serialized, bool notify = true) =>
Task.Run(() => _httpReplicator.Replicate(serialized))
.ContinueWith((replicated) =>
{
if (notify)
{
Replicated?.Invoke(this, new ReplicatedOneEvent { Id = id } );
}
});
public void Replicate(Dictionary<Guid, string> serialized, bool notify = true) =>
Task.Run(() => _httpReplicator.Replicate(serialized))
.ContinueWith((replicated) =>
{
if (notify)
{
Replicated?.Invoke(this, new ReplicatedManyEvent { Ids = replicated.Result });
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment