garbagebox
v1.1.1
Published
Typescript in Javascript. Gives you the types and leaves behind the pain.
Downloads
6
Readme
Garbagebox
Type safe Javascript and uhh, Multi-threading
How do I do it
You just do it
npm i garbagebox
Supported types
box.string
box.number
box.boolean
box.object
box.function
box.symbol
box.null
box.undefined
GarbagePacks
const myPack = box.pack(() => {
console.log('Hello world!');
});
myPack.data(); // Returns () => { console.log('Hello world!'); }
myPack.type(); // Returns 'GarbagePack'
myPack.run(); // Returns {}
const myPack2 = box.pack(() => {
module.exports = 'Hello world!';
});
myPack.run(); // Returns 'Hello world!'
Multi-Threading
const myPack = box.pack(() => {
console.log('Running in worker!');
send('Hello world!');
receive((message) => {
console.log('From parent thread: ' + message);
});
});
const spawner = box.spawn(myPack);
spawner.onMessage((data) => { console.log('From thread: ' + data); });
spawner.send('Hello World!');
Type safety
const x = box.new(box.number, 2);
const y = box.new(box.number, 3);
x.get() + y.get() // Returns 5
x.set(5)
x.get() + y.get() // Returns 8