Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
9795489d67 | |||
28733cbd73 | |||
f12335ea62 | |||
f12a92660f | |||
c81800cfab | |||
05b94469b5 | |||
eda415893c | |||
630b7661d9 | |||
702c0164a2 | |||
0220252b28 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
115
.gitlab-ci.yml
115
.gitlab-ci.yml
@ -1,79 +1,84 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
variables:
|
||||
GIT_STRATEGY: clone
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
@ -81,35 +86,37 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:18-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -117,5 +124,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
52
README.md
52
README.md
@ -1,52 +0,0 @@
|
||||
# @pushrocks/smartspawn
|
||||
smart subprocess handling
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartspawn)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartspawn)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartspawn)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartspawn/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartspawn/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartspawn/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartspawn)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartspawn)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
### Understand the Purpose
|
||||
|
||||
smartipc makes it easy to spawn tasks into subprocesses without loosing control over what those processes do.
|
||||
You can transparently call functions and expect returned data using promises.
|
||||
|
||||
### How To
|
||||
|
||||
**Master.ts:**
|
||||
|
||||
```javascript
|
||||
import * as smartspawn from 'smartspawn';
|
||||
smartspawn.setBasePathArg(__dirname); // if you want to avoid typings out full paths every time
|
||||
|
||||
let myThread = new smartspawn.Thread('worker');
|
||||
myThread.send('someMessageOrObject').then(messageResponse => {
|
||||
console.log(messageResponse);
|
||||
});
|
||||
```
|
||||
|
||||
**worker.ts**
|
||||
|
||||
```javascript
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
@ -9,11 +9,12 @@
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartspawn",
|
||||
"shortDescription": "smart subprocess handling",
|
||||
"description": "smart subprocess handling",
|
||||
"npmPackagename": "@pushrocks/smartspawn",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
15194
package-lock.json
generated
15194
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@ -1,13 +1,15 @@
|
||||
{
|
||||
"name": "@pushrocks/smartspawn",
|
||||
"version": "2.0.6",
|
||||
"version": "3.0.1",
|
||||
"private": false,
|
||||
"description": "smart subprocess handling",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -21,27 +23,30 @@
|
||||
"homepage": "https://gitlab.com/pushrocks/smartipc#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"spawn-wrap": "^1.4.2",
|
||||
"threads": "^0.12.1"
|
||||
"spawn-wrap": "^2.0.0",
|
||||
"threads": "1.7.0",
|
||||
"tiny-worker": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.11",
|
||||
"@types/node": "^12.7.2",
|
||||
"tslint": "^5.19.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
64
readme.md
Normal file
64
readme.md
Normal file
@ -0,0 +1,64 @@
|
||||
# @pushrocks/smartspawn
|
||||
smart subprocess handling
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartspawn)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartspawn)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartspawn)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartspawn/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
### Understand the Purpose
|
||||
|
||||
smartipc makes it easy to spawn tasks into subprocesses without loosing control over what those processes do.
|
||||
You can transparently call functions and expect returned data using promises.
|
||||
|
||||
### How To
|
||||
|
||||
**Master.ts:**
|
||||
|
||||
```javascript
|
||||
import * as smartspawn from 'smartspawn';
|
||||
smartspawn.setBasePathArg(__dirname); // if you want to avoid typings out full paths every time
|
||||
|
||||
let myThread = new smartspawn.Thread('worker');
|
||||
myThread.send('someMessageOrObject').then((messageResponse) => {
|
||||
console.log(messageResponse);
|
||||
});
|
||||
```
|
||||
|
||||
**worker.ts**
|
||||
|
||||
```javascript
|
||||
|
||||
```
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
58
test/test.ts
58
test/test.ts
@ -1,61 +1,7 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartspawn from '../ts/index';
|
||||
import * as smartspawn from '../ts/index.js';
|
||||
|
||||
let testThreadFunction: smartspawn.ThreadFunction;
|
||||
let testThread: smartspawn.Thread;
|
||||
let testPool: smartspawn.Pool;
|
||||
|
||||
/**
|
||||
* create a normal ThreadFunction
|
||||
*/
|
||||
tap.test('should create an instance of ThreadFunction', async () => {
|
||||
testThreadFunction = new smartspawn.ThreadFunction((input, done) => {
|
||||
let url = require('url');
|
||||
done(url.parse(input));
|
||||
});
|
||||
const message = await testThreadFunction.send('https://google.com');
|
||||
console.log(message);
|
||||
testThreadFunction.kill();
|
||||
});
|
||||
|
||||
tap.test('should create an instance of Thread', async () => {
|
||||
smartspawn.setWorkerBasePath(__dirname);
|
||||
testThread = new smartspawn.Thread('../testassets/child.ts');
|
||||
testThread.enableTypeScript();
|
||||
const message = await testThread.send('https://google.com');
|
||||
console.log(message);
|
||||
testThread.kill();
|
||||
});
|
||||
|
||||
tap.test('should not spawn when nothing is sent', async () => {
|
||||
smartspawn.setWorkerBasePath(__dirname);
|
||||
let testThread = new smartspawn.Thread('../testassets/child.ts');
|
||||
});
|
||||
|
||||
tap.test('should run in a Pool', async () => {
|
||||
let testPool = new smartspawn.Pool();
|
||||
let testThread = new smartspawn.Thread('../testassets/child.ts');
|
||||
testThread.assignToPool(testPool);
|
||||
|
||||
// first run
|
||||
let message = await testThread.send('what');
|
||||
expect(message).to.equal('what');
|
||||
console.log(message);
|
||||
|
||||
// second run
|
||||
message = await testThread.send('another');
|
||||
expect(message).to.equal('another');
|
||||
console.log(message);
|
||||
|
||||
// kill all
|
||||
testThread.assignedPool.pool.killAll();
|
||||
});
|
||||
|
||||
tap.test('should once', async () => {
|
||||
let testThread = new smartspawn.Thread('../testassets/child.ts');
|
||||
const message = await testThread.sendOnce('what');
|
||||
expect(message).to.equal('what');
|
||||
});
|
||||
tap.test('should create a simple test function', async () => {});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartspawn',
|
||||
version: '3.0.1',
|
||||
description: 'smart subprocess handling'
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
export * from './smartspawn.classes.thread';
|
||||
export * from './smartspawn.classes.threadfunction';
|
||||
export * from './smartspawn.classes.threadsimple';
|
||||
export * from './smartspawn.classes.pool';
|
||||
export * from './smartspawn.wrap';
|
||||
export * from './smartspawn.classes.threadsimple.js';
|
||||
export * from './smartspawn.wrap.js';
|
||||
|
||||
export * from 'threads';
|
||||
|
@ -1,6 +0,0 @@
|
||||
// ==============
|
||||
// This file handles clustering of nodejs programs
|
||||
// ==============
|
||||
import * as plugins from './smartspawn.plugins';
|
||||
|
||||
export class Cluster {}
|
@ -1,13 +0,0 @@
|
||||
import * as plugins from './smartspawn.plugins';
|
||||
|
||||
export class Pool {
|
||||
pool;
|
||||
|
||||
// the constructor for pool
|
||||
constructor() {
|
||||
this.pool = new plugins.threads.Pool();
|
||||
}
|
||||
run(workerPathArg: string) {
|
||||
return this.pool.run(workerPathArg);
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
import * as plugins from './smartspawn.plugins';
|
||||
import * as paths from './smartspawn.paths';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
import { Pool } from './smartspawn.classes.pool';
|
||||
import { startSpawnWrap, endSpawnWrap } from './smartspawn.wrap';
|
||||
|
||||
export let workerBasePath: string = null;
|
||||
|
||||
export const setWorkerBasePath = (basePathArg: string) => {
|
||||
workerBasePath = basePathArg;
|
||||
plugins.threads.config.set({
|
||||
basepath: {
|
||||
node: workerBasePath
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export class Thread {
|
||||
thread;
|
||||
workerPath: string;
|
||||
running: boolean = false;
|
||||
assignedPool: Pool = null;
|
||||
constructor(filePathArg: string) {
|
||||
this.workerPath = filePathArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
* spawns it and keeps running
|
||||
*/
|
||||
send<T>(message: any): Promise<T> {
|
||||
let done = smartpromise.defer<T>();
|
||||
this._checkSpawn();
|
||||
this.thread.send(message);
|
||||
this.thread.on('message', (message: T) => {
|
||||
done.resolve(message);
|
||||
});
|
||||
this.thread.on('done', (job, message: T) => {
|
||||
done.resolve(message);
|
||||
});
|
||||
this.thread.on('error', err => {
|
||||
done.reject(err);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a command once and then kills the child process
|
||||
*/
|
||||
sendOnce<T>(message): Promise<T> {
|
||||
let done = smartpromise.defer<T>();
|
||||
this.send<T>(message).then(message => {
|
||||
done.resolve(message);
|
||||
this.kill();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* kills the thread
|
||||
*/
|
||||
kill() {
|
||||
this.thread.kill();
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
assignToPool(poolArg: Pool) {
|
||||
this.assignedPool = poolArg;
|
||||
}
|
||||
|
||||
enableTypeScript() {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
private _checkSpawn() {
|
||||
if (!this.running && !this.assignedPool) {
|
||||
this.running = true;
|
||||
this.thread = plugins.threads.spawn(this.workerPath);
|
||||
} else if (!this.running && this.assignedPool) {
|
||||
this.running = true;
|
||||
this.thread = this.assignedPool.run(this.workerPath);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
import * as plugins from './smartspawn.plugins';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export interface IThreadFunction {
|
||||
(input, done): void;
|
||||
}
|
||||
|
||||
export class ThreadFunction {
|
||||
thread;
|
||||
constructor(functionArg: IThreadFunction) {
|
||||
this.thread = plugins.threads.spawn(functionArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a message to the spawned process
|
||||
*/
|
||||
send<T>(message: any): Promise<T> {
|
||||
let done = smartpromise.defer<T>();
|
||||
this.thread
|
||||
.send(message)
|
||||
.on('message', (message: T) => {
|
||||
done.resolve(message);
|
||||
})
|
||||
.on('error', err => {
|
||||
done.reject(err);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
kill() {
|
||||
this.thread.kill();
|
||||
}
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
import * as plugins from './smartspawn.plugins';
|
||||
import * as plugins from './smartspawn.plugins.js';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as childProcess from 'child_process';
|
||||
|
||||
import { workerBasePath } from './smartspawn.classes.thread';
|
||||
|
||||
export class ThreadSimple {
|
||||
workerPath: string;
|
||||
threadChildProcess: childProcess.ChildProcess;
|
||||
forkOptions: childProcess.ForkOptions;
|
||||
argvArgs: string[];
|
||||
public workerPath: string;
|
||||
public threadChildProcess: childProcess.ChildProcess;
|
||||
public forkOptions: childProcess.ForkOptions;
|
||||
public argvArgs: string[];
|
||||
constructor(
|
||||
filePathArg: string,
|
||||
argvArgs: string[] = [],
|
||||
@ -19,17 +17,13 @@ export class ThreadSimple {
|
||||
this.argvArgs = argvArgs;
|
||||
}
|
||||
|
||||
run() {
|
||||
let done = smartpromise.defer<childProcess.ChildProcess>();
|
||||
let forkPath = (() => {
|
||||
if (workerBasePath) {
|
||||
return plugins.path.join(workerBasePath, this.workerPath);
|
||||
} else {
|
||||
return this.workerPath;
|
||||
}
|
||||
})();
|
||||
public async start() {
|
||||
const forkPath = this.workerPath;
|
||||
this.threadChildProcess = childProcess.fork(forkPath, this.argvArgs, this.forkOptions);
|
||||
done.resolve(this.threadChildProcess);
|
||||
return done.promise;
|
||||
return this.threadChildProcess;
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
this.threadChildProcess.kill();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartspawn.plugins';
|
||||
import * as plugins from './smartspawn.plugins.js';
|
||||
|
||||
export const packageBase = plugins.path.join(__dirname, '../');
|
||||
export const typescriptwrapJs = plugins.path.join(packageBase, 'assets/typescriptwrap.js');
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as path from 'path';
|
||||
const threads = require('threads');
|
||||
import * as threads from 'threads';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export { path, smartpromise, threads };
|
||||
|
@ -3,8 +3,8 @@ import * as spawnWrap from 'spawn-wrap';
|
||||
let unwrap: any = null;
|
||||
|
||||
export const startSpawnWrap = (filePath: string, cliArgs: string[] = [], envArgs: any = {}) => {
|
||||
let spawnArray = [filePath];
|
||||
for (let cliArg of cliArgs) {
|
||||
const spawnArray = [filePath];
|
||||
for (const cliArg of cliArgs) {
|
||||
spawnArray.push(cliArg);
|
||||
}
|
||||
unwrap = spawnWrap(spawnArray, envArgs);
|
||||
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user