All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mperry.fg.SimpleIOExtension.groovy Maven / Gradle / Ivy

There is a newer version: 0.8
Show newest version
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