Skip to content

Instantly share code, notes, and snippets.

@johnazariah
Created January 27, 2015 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnazariah/527287a190a14a73b35d to your computer and use it in GitHub Desktop.
Save johnazariah/527287a190a14a73b35d to your computer and use it in GitHub Desktop.
Orleans + F# (async issue)
type SyncXeroPrivateApplicationGrain() =
inherit GrainBase()
interface ISyncXeroPrivateApplicationGrain with
member this.SynchronizeAsync() =
let orleansTaskScheduler = TaskScheduler.Current
async {
let companyFile = XeroCompanyFile ()
let guid =
match companyFile.CompanyFileIdentifier with
| CompanyFileIdentifier _guid -> _guid
let uri = companyFile |> saveCompanyFile companyFile.CompanyFileIdentifier
//Filthy hack to get the code to run on the orleans task scheduler
do! Task.Factory.StartNew((fun () ->
let plotGrain = GenerateAccountBalanceCsvGrainFactory.GetGrain(0L)
plotGrain.GenerateCsvAsync(guid)), CancellationToken.None, TaskCreationOptions.None, orleansTaskScheduler).Unwrap()
|> Async.AwaitTask |> Async.Ignore
return uri
}
|> Async.StartAsTask
@johnazariah
Copy link
Author

In the code above, there really shouldn't be a Task.Factory.StartNew inside the async {}; what is desired is the ability to just 'do! plotGrain.Generate...' to asynchronously call the plotGrain grain's method!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment