Skip to content

Commit

Permalink
example doc wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Aug 20, 2021
1 parent 27ee9f1 commit 6948c7c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/api/esm.md
Expand Up @@ -828,6 +828,30 @@ const require = createRequire(cwd() + '/<preload>');
}
```
In order to allow communication between the application and the loader another
argument is provided to the preload code `port`. This is available as an
parameter to the loader hook and inside of the source text returned by the hook.
Some care must be taken in order to properly `ref()` and `unref()` the
`MessagePort` to prevent a process from being in a state where it won't close
normally.
```js
/**
* This example causes
* @param {object} utilities
* @param {MessagePort} utilities.port
*/
export function getGlobalPreloadCode({port}) {
port.onmessage = (evt) => {
// ...
};
return `\
port.postMessage('I went to the Loader and back');
port.onmessage = eval;
`;
}
```
### Examples
The various loader hooks can be used together to accomplish wide-ranging
Expand Down

0 comments on commit 6948c7c

Please sign in to comment.