Search in sources :

Example 1 with Callback

use of php.runtime.common.Callback in project jphp by jphp-compiler.

the class WrapPromise method resolve.

@Signature
public static WrapPromise resolve(Environment env, Memory result) {
    if (result.instanceOf(WrapPromise.class)) {
        WrapPromise promise = new WrapPromise(env);
        promise.__construct(env, new RunnableInvoker(env, new Callback<Memory, Memory[]>() {

            @Override
            public Memory call(Memory[] args) {
                try {
                    return ObjectMemory.valueOf(promise.then(env, Invoker.create(env, args[0]), Invoker.create(env, args[1])));
                } catch (Exception e) {
                    env.forwardThrow(e);
                    return Memory.NULL;
                }
            }
        }));
        return promise;
    } else {
        return new WrapPromise(env, new Callback<Memory, Memory[]>() {

            @Override
            public Memory call(Memory[] args) {
                // resolve.
                return Invoker.create(env, args[0]).callAny(result);
            }
        });
    }
}
Also used : Callback(php.runtime.common.Callback) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) RunnableInvoker(php.runtime.invoke.RunnableInvoker) BaseBaseException(php.runtime.lang.exception.BaseBaseException) JavaException(php.runtime.ext.java.JavaException)

Aggregations

Memory (php.runtime.Memory)1 Callback (php.runtime.common.Callback)1 JavaException (php.runtime.ext.java.JavaException)1 RunnableInvoker (php.runtime.invoke.RunnableInvoker)1 BaseBaseException (php.runtime.lang.exception.BaseBaseException)1 ArrayMemory (php.runtime.memory.ArrayMemory)1 ObjectMemory (php.runtime.memory.ObjectMemory)1 StringMemory (php.runtime.memory.StringMemory)1