Skip to content

Instantly share code, notes, and snippets.

@ericgla
Created July 19, 2019 23:57
Show Gist options
  • Save ericgla/990071500d0b7d49ab98aff56d9b872b to your computer and use it in GitHub Desktop.
Save ericgla/990071500d0b7d49ab98aff56d9b872b to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Orleans;
using System.Threading;
namespace GrainCollection
{
public interface ICancellableTask : IGrainWithIntegerKey
{
Task ProcessNudgeEvent();
}
public class CancellableTaskGrain : Grain, ICancellableTask
{
private CancellationTokenSource _cts;
public Task ProcessNudgeEvent()
{
if (_cts != null)
{
_cts.Cancel();
_cts.Dispose();
}
_cts = new CancellationTokenSource();
return Task.Factory.StartNew(() =>
{
// invoke some long running method
}, _cts.Token);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment