wilton.js  v202103141
 All Namespaces Functions
esm Namespace Reference

wilton/esm
Export Wilton API as a ES module. More...

Detailed Description

This module allows client code to import Wilton as a ES module.

All Wilton API is exported as a single wilton variable, that must be imported first and then can be desctructured to access separate "submodules". These submodules (and their corresponding native libraries) are loaded lazily.

When ES modules are used as callbackScripts to be invoked (possibly in another thread) from native code, they must be specified using full path (including protocol prefix) to JS file in esmodule attribute. Arguments can be provided to such callbackScripts using args attribute, but only String, Integer and Boolean arguments are supported. Arguments can be accessed from ES module using import.meta.args. func attribute is not supported for ES modules.

Usage example:

import wilton from "wilton";
const { Channel, thread } = wilton;
var chan = new Channel("...");
// run foo.js in another thread
var threadExitChan = thread.run({
callbackScript: {
esmodule: `${import.meta.dir}/foo.js`
}
});