Skip to content

Instantly share code, notes, and snippets.

@nicholashagen
Created March 6, 2012 23:09
Show Gist options
  • Save nicholashagen/1989663 to your computer and use it in GitHub Desktop.
Save nicholashagen/1989663 to your computer and use it in GitHub Desktop.
Groovy Closure to Callable
// anonymously invoke a closure into callable and submit to executor
// this fails w/o the explicit (Callable) since it converts it to Runnable
def executor = java.util.concurrent.Executors.newFixedThreadPool(5)
def future = executor.submit((java.util.concurrent.Callable) {
'TEST'
})
assert('TEST' == future.get())
@dminkovsky
Copy link

can also do

def future = executor.submit({ 'TEST' } as Callable)

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