start implementation
This commit is contained in:
parent
5ce83601b4
commit
f0f2761949
@ -18,14 +18,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartipc#README",
|
"homepage": "https://gitlab.com/pushrocks/smartipc#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lodash": "^4.14.36",
|
"@types/lodash": "^4.14.50",
|
||||||
"beautylog": "^5.0.23",
|
"beautylog": "^6.0.0",
|
||||||
"lodash": "^4.16.2",
|
"lodash": "^4.17.4",
|
||||||
|
"threads": "^0.7.2",
|
||||||
"typings-global": "^1.0.14"
|
"typings-global": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"@types/should": "^8.1.30",
|
||||||
"should": "^11.1.0",
|
"should": "^11.1.2",
|
||||||
"typings-test": "^1.0.3"
|
"typings-test": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
test/child.d.ts
vendored
Normal file
0
test/child.d.ts
vendored
Normal file
4
test/child.js
Normal file
4
test/child.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
"use strict";
|
||||||
|
const smartipc = require("../dist/index");
|
||||||
|
let localChild = new smartipc.IpcChild({});
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjaGlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMENBQXlDO0FBRXpDLElBQUksVUFBVSxHQUFHLElBQUksUUFBUSxDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUMsQ0FBQSJ9
|
@ -1,22 +0,0 @@
|
|||||||
import * as plugins from './smartipc.plugins'
|
|
||||||
import { IpcTarget } from './smartipc.classes.ipctarget'
|
|
||||||
|
|
||||||
export interface IpcChildConstructorOptions {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultOptions: IpcChildConstructorOptions = {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class Ipcclient represents the child process
|
|
||||||
*/
|
|
||||||
export class IpcChild extends IpcTarget {
|
|
||||||
constructor(optionsArg: IpcChildConstructorOptions) {
|
|
||||||
super({alias: 'child'})
|
|
||||||
}
|
|
||||||
call(ipctarget,targetFunction,dataArg) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
import * as plugins from './smartipc.plugins'
|
|
||||||
import { IpcTarget } from './smartipc.classes.ipctarget'
|
|
||||||
|
|
||||||
export interface IIpcServeOptions {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultOptions: IIpcServeOptions = {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IIpcChildProcess {
|
|
||||||
alias: string
|
|
||||||
filePath: string
|
|
||||||
childProcess: plugins.childProcess.ChildProcess
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class Ipcserve is represents the master process for any chil processes
|
|
||||||
*/
|
|
||||||
export class IpcMaster extends IpcTarget {
|
|
||||||
ipcOptions: IIpcServeOptions
|
|
||||||
childProcessArray: IIpcChildProcess[]
|
|
||||||
constructor(ipcOptionsArg: IIpcServeOptions) {
|
|
||||||
super({alias: 'master'})
|
|
||||||
this.ipcOptions = plugins.lodash.merge({},defaultOptions,ipcOptionsArg)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* spawns a child process
|
|
||||||
*/
|
|
||||||
spawnProcess(filePath: string, alias: string) {
|
|
||||||
|
|
||||||
let childProcess = plugins.childProcess.fork('ls', ['-lh', '/usr'])
|
|
||||||
|
|
||||||
childProcess.stdout.on('data', (data) => {
|
|
||||||
console.log(`stdout: ${data}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
childProcess.stderr.on('data', (data) => {
|
|
||||||
console.log(`stderr: ${data}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
childProcess.on('close', (code) => {
|
|
||||||
console.log(`child process exited with code ${code}`)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
import * as plugins from './smartipc.plugins'
|
|
||||||
|
|
||||||
export interface ITargetConstructorOptions {
|
|
||||||
alias: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export class IpcTarget {
|
|
||||||
alias: string
|
|
||||||
private funcArray: any[]
|
|
||||||
|
|
||||||
constructor(optionsArg: ITargetConstructorOptions) {
|
|
||||||
this.alias = optionsArg.alias
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* registers a function
|
|
||||||
*/
|
|
||||||
register(funcArrayArg: any[]) {
|
|
||||||
for (let funcItem of funcArrayArg){
|
|
||||||
this.funcArray.push(funcItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
32
ts/smartipc.classes.thread.ts
Normal file
32
ts/smartipc.classes.thread.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import 'typings-global'
|
||||||
|
|
||||||
|
let threads = require('threads')
|
||||||
|
|
||||||
|
export interface IThreadFunction {
|
||||||
|
(input, done): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Thread {
|
||||||
|
thread
|
||||||
|
constructor(functionArg: IThreadFunction) {
|
||||||
|
this.thread = threads.spawn(functionArg)
|
||||||
|
this.thread.on('error', function() {
|
||||||
|
|
||||||
|
})
|
||||||
|
this.thread.on('exit' function() {
|
||||||
|
|
||||||
|
})
|
||||||
|
this.thread.on('message')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sends a message to the spawned process
|
||||||
|
*/
|
||||||
|
send(message) {
|
||||||
|
this.thread.send(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sends a message to
|
||||||
|
*/
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
import 'typings-global'
|
|
||||||
export import beautylog = require('beautylog')
|
|
||||||
export import lodash = require('lodash')
|
|
||||||
export import childProcess = require('child_process')
|
|
Loading…
Reference in New Issue
Block a user