Node's Perpetuum Mobile

    node_shm

    0.0.1 • Public • Published

    使用方式 | Usage

    const cluster=require('cluster');
    const shm=require('node_shm');
     
    var buf;
    if(cluster.isMaster){
        buf=shm.create(4096);//shm.create(size)
        cluster.fork().on('online',function(){
            this.send(buf.key);//send key
            setInterval(function(){
                console.log('[Master] Set buf[0]=%d',++buf[0]);
            },500);
        }).on('exit',() => process.exit());
    }else{
        process.on('message',function(message){
            buf=shm.get(message);//shm.get(key);
            setInterval(function(){
                console.log('[Worker] Get buf[0]=%d',buf[0]);
                if(buf[0]>10) process.exit();
            },500);
        });
    }

    Keywords

    Install

    npm i node_shm

    DownloadsWeekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Last publish

    Collaborators

    • a0000778