Skip to content

Commit

Permalink
Version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
radixxko committed Oct 10, 2018
1 parent ed3e0bc commit 64ea7da
Show file tree
Hide file tree
Showing 12 changed files with 678 additions and 331 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: node_js
node_js:
- "node"
- "9"
- "8"
script:
- npm test
after_success:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# liqd-ipc

[![NPM version](https://img.shields.io/npm/v/liqd-ipc.svg)](https://www.npmjs.com/package/liqd-ipc)
[![Build Status](https://travis-ci.org/radixxko/liqd-ipc.svg?branch=master)](https://travis-ci.org/radixxko/liqd-ipc)
[![Coverage Status](https://coveralls.io/repos/github/radixxko/liqd-ipc/badge.svg?branch=master)](https://coveralls.io/github/radixxko/liqd-ipc?branch=master)
[![NPM downloads](https://img.shields.io/npm/dm/liqd-ipc.svg)](https://www.npmjs.com/package/liqd-ipc)
[![Known Vulnerabilities](https://snyk.io/test/github/radixxko/liqd-ipc/badge.svg?targetFile=package.json)](https://snyk.io/test/github/radixxko/liqd-ipc?targetFile=package.json)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
52 changes: 46 additions & 6 deletions lib/ipc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

//const Flow = require('liqd-flow');
const Listeners = require('./listeners');
const Replies = require('./replies');
const Request = require('./request');
Expand All @@ -19,7 +20,21 @@ module.exports = class IPC
{
if( msg.__liqd_ipc.hasOwnProperty('reply') )
{
if( msg.__liqd_ipc.hasOwnProperty('error') )
/*if( msg.__liqd_ipc.flow )
{
const Flow = require('liqd-flow');
Flow.start(() =>
{
for( let key in msg.__liqd_ipc.flow )
{
Flow.set( key, msg.__liqd_ipc.flow[key].value, msg.__liqd_ipc.flow[key].frozen );
}
this._replies.resolve( msg.__liqd_ipc.reply, msg.__liqd_ipc );
});
}
else */if( msg.__liqd_ipc.hasOwnProperty('error') )
{
this._replies.reject( msg.__liqd_ipc.reply, msg.__liqd_ipc.error );
}
Expand All @@ -37,18 +52,38 @@ module.exports = class IPC
if( listener( request ) !== false ){ return; }
}

request.reject( 'IPC_UNHANDELED_CALL' );
request.reject( 'IPC_UNHANDLED_CALL' );
}
else if( msg.__liqd_ipc.hasOwnProperty('message') )
{
const topic = msg.__liqd_ipc.topic, message = new Message( this, msg.__liqd_ipc );
const listeners = this._listeners.get( 'message', msg.__liqd_ipc.topic ), message = new Message( this, msg.__liqd_ipc );

for( let listener of this._listeners.get( 'message', topic ))
if( listeners )
{
if( listener( message ) !== false ){ return; }
/*if( msg.__liqd_ipc.flow )
{
const Flow = require('liqd-flow');
Flow.start(() =>
{
for( let key in msg.__liqd_ipc.flow )
{
Flow.set( key, msg.__liqd_ipc.flow[key].value, msg.__liqd_ipc.flow[key].frozen );
}
for( let listener of listeners )
{
if( listener( message ) !== false ){ return; }
}
});
}
else */for( let listener of listeners )
{
if( listener( message ) !== false ){ return; }
}
}

message.reject( 'IPC_UNHANDELED_MESSAGE' );
message.reject( 'IPC_UNHANDLED_MESSAGE' );
}
else if( msg.__liqd_ipc.hasOwnProperty('event') )
{
Expand All @@ -70,6 +105,11 @@ module.exports = class IPC

_ipc_send( msg )
{
/*if( LIQD_FLOW && LIQD_FLOW.started )
{
msg.flow = LIQD_FLOW.scope();
}*/

this._port.postMessage ? this._port.postMessage({ __liqd_ipc: msg }) : this._port.send({ __liqd_ipc: msg });
}

Expand Down
18 changes: 17 additions & 1 deletion lib/replies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

//const Flow = require('liqd-flow');
const Cache = require('liqd-cache');
const TimedPromise = require('liqd-timed-promise');

Expand All @@ -13,11 +14,13 @@ module.exports = class Replies

create( callback )
{
//const flow = Flow.save();

return new TimedPromise(( resolve, reject, timeout ) =>
{
let id = ( this._iterator = ( this._iterator % Number.MAX_SAFE_INTEGER ) + 1 );

this._replies.set( id, { resolve, reject }, timeout );
this._replies.set( id, { resolve, reject/*, flow*/ }, timeout );

callback( id, timeout );
});
Expand All @@ -32,6 +35,19 @@ module.exports = class Replies
this._replies.delete( id );

handler.resolve( value );
/*
let scope = Flow.scope();
console.log( 'Restorujem', scope );
handler.flow.restore( () =>
{
for( let key in scope )
{
Flow.set( key, scope[key].value, scope[key].frozen );
}
handler.resolve( value );
});*/
}

return Boolean( handler );
Expand Down
25 changes: 15 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "liqd-ipc",
"description": "NodeJS Cluster/WorkerThread IPC",
"version": "1.0.0",
"version": "1.0.1",
"author": "radixxko",
"license": "MIT",
"main": "lib/ipc.js",
"files": [
"lib/"
],
"scripts": {
"test": "nyc mocha",
"test": "export NODE_OPTIONS=\"--experimental-worker\" && nyc mocha",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"repository": {
Expand All @@ -24,8 +24,9 @@
"liqd"
],
"dependencies": {
"liqd-cache": "^1.0.0",
"liqd-timed-promise": "^1.2.0"
"liqd-cache": "^1.0.2",
"liqd-flow": "^1.2.5",
"liqd-timed-promise": "^1.2.1"
},
"devDependencies": {
"coveralls": "^3.0.2",
Expand Down

0 comments on commit 64ea7da

Please sign in to comment.