Created
July 19, 2019 23:57
-
-
Save ericgla/990071500d0b7d49ab98aff56d9b872b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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