com.github.mperry.fg.SimpleIOExtension.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalgroovy-main Show documentation
Show all versions of functionalgroovy-main Show documentation
FunctionalGroovy enhances FunctionalJava for Groovy
package com.github.mperry.fg
import fj.P1
import groovy.transform.TypeChecked
import groovyx.gpars.GParsPoolUtil
import groovyx.gpars.scheduler.FJPool
import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Future
@TypeChecked
class SimpleIOExtension {
public static groovyx.gpars.dataflow.Promise asyncGpars(SimpleIO io) {
def p = new FJPool()
def c = { -> io.run() }
def af = GParsPoolUtil.asyncFun(c, p)
def r = af.call()
(groovyx.gpars.dataflow.Promise) r
}
public static Future asyncJava(SimpleIO io) {
asyncJava(io, SimpleIO.defaultService())
}
public static Future asyncJava(SimpleIO io, ExecutorService s) {
def c = { -> io.run() }
def r = s.submit(c as Callable)
r
}
public static fj.control.parallel.Promise asyncFj(SimpleIO io) {
def c = { ->
io.run()
}
def r = fj.control.parallel.Promise.promise(SimpleIO.defaultStrategy(), c as P1)
r
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy