New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

napa-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

napa-loader

## Install

2.0.2
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Napa-Loader

Install

npm install --save napa-loader

Usage

see test

1. Create a module

// test-module.js
let state = 'init'

function changeState(_state) { state = _state }

function getState() { return state }

function fib(n) {
    if (n === 0) return 0;
    else if (n === 1) return 1;
    else return fib(n - 1) + fib(n - 2)
}

module.exports = { fib, changeState, getState }

2. Load module by zrequire(<module_path>)


// Create a zone and init by load test-module.js
const test_module  = await zrequire('./test-module',  // same as require()
    { broadcast_funcs: ['changeState'] }) // mask 'changeState()' function will change environment and broadcast to all threads

// It is same as an normal module, but wrapped by Promise.
assert(await test_module.fib(40) === require('./test-module').fib(40))

// broadcast function can change all threads' environment
// note: broadcast function cannot return anything
await test_module.changeState('hello napajs')
assert(await test_module.getState() === 'hello napajs')

FAQs

Package last updated on 13 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts