Skip to content

Instantly share code, notes, and snippets.

@tednaleid
Created April 30, 2016 03:39
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 tednaleid/4955c324b93312905d960bd12071f434 to your computer and use it in GitHub Desktop.
Save tednaleid/4955c324b93312905d960bd12071f434 to your computer and use it in GitHub Desktop.
import ratpack.exec.Blocking
import ratpack.handling.Context
import ratpack.groovy.test.embed.GroovyEmbeddedApp
@GrabResolver(name = 'jcenter', root = 'http://jcenter.bintray.com/')
@GrabExclude('org.codehaus.groovy:groovy-all')
@Grab('org.slf4j:slf4j-simple:1.7.12')
@Grab('io.ratpack:ratpack-groovy:1.3.3')
@Grab('io.ratpack:ratpack-rx:1.3.3')
@Grab('io.ratpack:ratpack-groovy-test:1.3.3')
GroovyEmbeddedApp app = GroovyEmbeddedApp.of {
handlers {
all { Context context ->
println "A. Original compute thread: ${Thread.currentThread().name}"
Blocking.exec { ->
context.render "hello from blocking" // pretend blocking work
println "B. Blocking thread : ${Thread.currentThread().name}"
}
println "C. Original compute thread: ${Thread.currentThread().name}"
}
}
}.test {
assert getText() == "hello from blocking"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment