Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabiospampinato/siero-worker
A managed worker that can be interacted with via Siero.
https://github.com/fabiospampinato/siero-worker
deserialization environment plugin rpc sandbox serialization siero worker
Last synced: about 2 months ago
JSON representation
A managed worker that can be interacted with via Siero.
- Host: GitHub
- URL: https://github.com/fabiospampinato/siero-worker
- Owner: fabiospampinato
- License: mit
- Created: 2024-01-30T18:23:15.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2024-04-04T23:09:56.000Z (10 months ago)
- Last Synced: 2024-11-13T01:41:49.314Z (2 months ago)
- Topics: deserialization, environment, plugin, rpc, sandbox, serialization, siero, worker
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Siero Worker
A managed worker that can be interacted with via [Siero](https://github.com/fabiospampinato/siero).
This package creates a worker designed to receive some APIs and then execute untrusted plugins, but it could be used in various different ways.
## Install
```sh
npm install --save siero-worker
```## Usage
```ts
import SieroWorker from 'siero-worker';// Let's create a new worker
const worker = new SieroWorker ();
// Let's pass it a value and register it on the global scope
const MyApp = {
sum: ( a, b ) => {
return a + b;
},
multiply: ( a, b ) => {
return a * b;
}
};worker.global ( 'MyApp', MyApp );
// Let's now pass it some code to evaluate inside the worker
// For convenience here we are using a simple serializable function
// In real scenarios the code that you may want to evaluate in the worker would probably be bundledconst plugin = async () => {
const sumResult = await MyApp.sum ( 2, 3 ); // => 5
const multiplyResult = await MyApp.multiply ( 2, 3 ); // => 6
};worker.eval ( `(${plugin.toString ()})()` );
// Let's now terminate the worker
worker.terminate ();
```## License
MIT © Fabio Spampinato