Skip to content

Instantly share code, notes, and snippets.

@timyates
Created January 24, 2011 10:59
Show Gist options
  • Save timyates/793075 to your computer and use it in GitHub Desktop.
Save timyates/793075 to your computer and use it in GitHub Desktop.
Playing around with HawtDispatch examples in Groovy
@Grab( 'org.fusesource.hawtdispatch:hawtdispatch:1.1' )
import org.fusesource.hawtdispatch.*
import static org.fusesource.hawtdispatch.Dispatch.*
import java.util.concurrent.Semaphore
done = new Semaphore( 1 - ( 1000 * 1000 ) )
queue = createQueue()
source = createSource EventAggregators.INTEGER_ADD, queue
source.setEventHandler {
count = source.data
println "got: $count"
done.release count
}
source.resume()
// Produce 1,000,000 concurrent merge events
(0..<1000).each { i ->
globalQueue.execute {
(0..<1000).each { j ->
source.merge 1
}
}
}
// Wait for all the event to arrive.
done.acquire()
@timyates
Copy link
Author

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