Skip to content

Instantly share code, notes, and snippets.

@AlexCuse
Created June 7, 2011 23:00
Show Gist options
  • Save AlexCuse/1013392 to your computer and use it in GitHub Desktop.
Save AlexCuse/1013392 to your computer and use it in GitHub Desktop.
parallel still not working for some reason
module Program
#light
open System.Threading
open StructureMap
open BrewTelligence.Domain
open BrewTelligence.Search.Indexing
open BrewTelligence.ApplicationServices
open BrewTelligence.ApplicationServices.Messaging
printfn "indexing in: %s" BrewTelligence.Search.FileSystem.IndexDirectory.Path;
ObjectFactory.Initialize(fun x -> x.AddRegistry (new SearchRegistry()))
let write<'T> (item:'T) =
printfn "writing: %A" item
ObjectFactory.GetAllInstances<Indexer<'T>>() |> Seq.iter (fun idxr -> idxr.Index item)
let indexActions<'T when 'T: not struct and 'T:null and 'T:equality> =
let p = QueueProvider<'T>.Create()
seq {
while true do
let obj = p.Dequeue()
if obj = null then
yield None
Thread.Sleep 500 //this necessary?
else
yield Some(async { write obj })
}
try
indexActions<Yeast>
|> Seq.merge indexActions<Addition>
|> Seq.merge indexActions<Hop>
|> Seq.merge indexActions<Malt>
|> Seq.merge indexActions<Recipe>
|> OptionSeq.unwrapAndDiscardEmpty
//|> Async.Parallel //not sure why this isn't working
|> Seq.iter Async.RunSynchronously
|> ignore
finally
SearchRegistry.DeRegister()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment