/** * Unpack and execute a nodejs library. Once unpack this method will execute one of these scripts * in the following order: 1) [library].js; 2) main.js; 3) index.js. * * The first file found will be executed. * * @param library Library to unpack and execute this library. * @throws Throwable If something goes wrong. */ public void exec(final String library, final Throwing.Consumer<V8> callback) throws Throwable { Path basedir = deploy(library); List<String> candidates = Arrays.asList( basedir.getFileName().toString() + ".js", "main.js", "index.js"); Path main = candidates.stream() .map(basedir::resolve) .filter(Files::exists) .findFirst() .orElseThrow(() -> new FileNotFoundException(candidates.toString())); callback.accept(node.getRuntime()); node.exec(main.toFile()); while (node.isRunning()) { node.handleMessage(); } }
@Override public void run() { try { nodeJS.isRunning(); } catch (Error e) { result[0] = e.getMessage().contains("Invalid V8 thread access"); } } });
private void runMessageLoop() { while (nodeJS.isRunning()) { nodeJS.handleMessage(); } }
/** * Unpack and execute a nodejs library. Once unpack this method will execute one of these scripts * in the following order: 1) [library].js; 2) main.js; 3) index.js. * * The first file found will be executed. * * @param library Library to unpack and execute this library. * @throws Throwable If something goes wrong. */ public void exec(final String library, final Throwing.Consumer<V8> callback) throws Throwable { Path basedir = deploy(library); List<String> candidates = Arrays.asList( basedir.getFileName().toString() + ".js", "main.js", "index.js"); Path main = candidates.stream() .map(basedir::resolve) .filter(Files::exists) .findFirst() .orElseThrow(() -> new FileNotFoundException(candidates.toString())); callback.accept(node.getRuntime()); node.exec(main.toFile()); while (node.isRunning()) { node.handleMessage(); } }