Skip to content

Instantly share code, notes, and snippets.

@kimukou
Created October 15, 2010 15:15
Show Gist options
  • Save kimukou/628356 to your computer and use it in GitHub Desktop.
Save kimukou/628356 to your computer and use it in GitHub Desktop.
@Grab(group='org.gparallelizer', module='gparallelizer', version='0.8.4')
import org.gparallelizer.Asynchronizer
output={msg,i,j->
println "${msg}:${i}:${j}"
}
echo={msg,i->println"$msg:$i"
for(int j=0;j<10;j++){
//println "${msg}:${i}:${j}"
output(msg,i,j)
}
}
m="HOGE";
println "-case A----------------------------------"
Asynchronizer.withAsynchronizer(2){es->
println "[P]es=${es.dump()}"
for(int i=0;i<4;i++){
int n =i;
es<<{echo(m+"_A",n)}
}
println "[A]es=${es.dump()}"
}
println "-case B----------------------------------"
Asynchronizer.withAsynchronizer(2){
def arr=[]
int loop=0
for(int i=0;i<4;i++){
b = echo.callAsync(m+"_B",i)
arr << b
loop++
if(loop==2){
arr.each{
println "it=${it.dump()}"
if(!it.isDone()){
it.get()
}
}
arr.removeAll()
loop=0
}
}
}
println "-case C----------------------------------"
Asynchronizer.withAsynchronizer(2){
for(int i=0;i<4;i++){
echo.callAsync(m+"_C",i)
}
}
println "-case D----------------------------------"
Asynchronizer.withAsynchronizer(2){
for(int i=0;i<4;i++){
echo.call(m+"_D",i)
}
}
println "-----------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment