private def invokeSynchronous(address, method, ...) { yield; // This is where it returns to runThreaded(). // This is where we enter in runSynchronized(); val result = native.invoke(address, method, ...); // See definition of invoke in initialize() for values of result. yield; // And return to runSynchronized(); // And the next runThreaded() enters again. return result[1]; } private def invokeDirect(address, method, ...) { val result = native.invoke(address, method, ...); // See definition of invoke in initialize() for values of result. if (result[0] == true) { return result[1]; } else { return invokeSynchronous(address, method, ...); } } def invoke(address, method, ...) { if (isDirect(address, method)) { return invokeDirect(address, method, ...); } else { return invokeSynchronous(address, method, ...); } }