31 Commits

Author SHA1 Message Date
83bcdc4eb0 update description 2024-05-29 14:16:25 +02:00
5c2f318158 3.0.3 2024-05-14 19:28:39 +02:00
e8043c5734 fix(core): update 2024-05-14 19:28:39 +02:00
b9805efa57 update tsconfig 2024-04-14 18:21:57 +02:00
a52a4ab7fd update tsconfig 2024-04-01 21:41:12 +02:00
ea609f83d7 update npmextra.json: githost 2024-04-01 19:59:44 +02:00
3db25512ee update npmextra.json: githost 2024-03-30 21:48:44 +01:00
5c2e3fea6c 3.0.2 2022-07-28 23:14:25 +02:00
7e5178d825 fix(core): update 2022-07-28 23:14:25 +02:00
9795489d67 3.0.1 2022-07-28 23:03:29 +02:00
28733cbd73 fix(core): update 2022-07-28 23:03:29 +02:00
f12335ea62 3.0.0 2022-07-28 22:35:17 +02:00
f12a92660f BREAKING CHANGE(core): switch to esm 2022-07-28 22:35:16 +02:00
c81800cfab 2.0.9 2019-08-23 00:30:02 +02:00
05b94469b5 fix(core): update 2019-08-23 00:30:01 +02:00
eda415893c 2.0.8 2019-08-22 10:42:47 +02:00
630b7661d9 fix(core): update 2019-08-22 10:42:47 +02:00
702c0164a2 2.0.7 2019-08-22 09:26:30 +02:00
0220252b28 fix(core): update 2019-08-22 09:26:30 +02:00
fcdcd4b929 2.0.6 2019-08-22 00:32:10 +02:00
c2f7e98481 fix(core): update 2019-08-22 00:32:09 +02:00
a2242105a1 2.0.5 2019-08-22 00:04:27 +02:00
44431e7d25 fix(core): update 2019-08-22 00:04:27 +02:00
3999015b23 2.0.4 2019-04-08 15:39:18 +02:00
77ad483a8a fix(core): update 2019-04-08 15:39:17 +02:00
904309564a 2.0.3 2019-04-08 15:13:48 +02:00
d8c03fd9ca fix(core): update 2019-04-08 15:13:47 +02:00
7e5c0fe678 2.0.2 2018-08-07 11:13:03 +02:00
93b44ba888 fix(core): update testing framework 2018-08-07 11:13:03 +02:00
30249ad254 2.0.1 2018-08-02 15:35:55 +02:00
07be849d2f fix(package): npm access level 2018-08-02 15:35:55 +02:00
26 changed files with 21724 additions and 1208 deletions

20
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
pages/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,126 +1,122 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
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:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci git mirror
- npmci npm prepare
- 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
snyk:
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm install -g snyk
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
- notpriv
- docker
allow_failure: true
# ====================
# test stage
# ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS:
testStable:
stage: test
script:
- 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
- notpriv
testSTABLE:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
- 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 stable
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
only:
- tags
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
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-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
@ -128,15 +124,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@ -1,57 +0,0 @@
# @pushrocks/smartspawn
smart subprocess handling
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartipc)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartipc)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartipc)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartipc/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartipc/badges/master/build.svg)](https://GitLab.com/pushrocks/smartipc/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartipc/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartipc/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartipc.svg)](https://www.npmjs.com/package/smartipc)
[![Dependency Status](https://david-dm.org/pushrocks/smartipc.svg)](https://david-dm.org/pushrocks/smartipc)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartipc/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartipc/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartipc/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartipc)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## 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.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -1,2 +1,2 @@
require('@gitzone/tsrun');
require('@git.zone/tsrun');
require('spawn-wrap').runMain()

View File

@ -7,5 +7,29 @@
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartspawn",
"description": "A node module for smart subprocess handling with support for promises and streamlined subprocess communication.",
"npmPackagename": "@push.rocks/smartspawn",
"license": "MIT",
"keywords": [
"subprocess",
"child_process",
"spawn",
"threading",
"multithreading",
"process management",
"async",
"promise"
]
}
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

15538
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +1,62 @@
{
"name": "@pushrocks/smartspawn",
"version": "2.0.0",
"description": "smart subprocess handling",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "@push.rocks/smartspawn",
"version": "3.0.3",
"private": false,
"description": "A node module for smart subprocess handling with support for promises and streamlined subprocess communication.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "tsrun test/test.ts",
"build": "echo \"Not needed for now\""
"test": "(tstest test/)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/smartipc.git"
"url": "https://code.foss.global/push.rocks/smartspawn.git"
},
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartipc/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartipc#README",
"homepage": "https://code.foss.global/push.rocks/smartspawn",
"dependencies": {
"@pushrocks/smartpromise": "^2.0.5",
"spawn-wrap": "^1.4.2",
"threads": "^0.8.1"
"@push.rocks/smartpromise": "^4.0.3",
"spawn-wrap": "^2.0.0",
"threads": "1.7.0",
"tiny-worker": "^2.2.0"
},
"devDependencies": {
"@gitzone/tsrun": "^1.1.9",
"@pushrocks/tapbundle": "^3.0.1",
"@types/node": "^10.5.5"
"@git.zone/tsbuild": "^2.1.11",
"@git.zone/tsrun": "^1.2.8",
"@git.zone/tstest": "^1.0.24",
"@push.rocks/tapbundle": "^5.0.4",
"@types/node": "^20.12.12"
},
"private": true
}
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
],
"keywords": [
"subprocess",
"child_process",
"spawn",
"threading",
"multithreading",
"process management",
"async",
"promise"
]
}

6651
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

120
readme.md Normal file
View File

@ -0,0 +1,120 @@
Given the provided files and their contents, the comprehensive documentation for using **`@push.rocks/smartspawn`** with TypeScript and in a manner that provides thorough examples and descriptions of features and scenarios is extensive. However, I'll outline a concise and informative usage guide that can serve as a helpful starting point. For an in-depth understanding and a complete reference to all features, further reading, exploration, and experimentation with the library are recommended.
# @push.rocks/smartspawn
smart subprocess handling
## Install
To install `@push.rocks/smartspawn`, open your terminal and run the following command:
```bash
npm install @push.rocks/smartspawn
```
This command fetches the package from npm and adds it to your project's dependencies.
## Usage
This guide uses TypeScript and ESM syntax to demonstrate how to utilize `@push.rocks/smartspawn` for smart subprocess handling in your application.
First, ensure that your TypeScript environment is set up to support ECMAScript modules (ESM). Your `tsconfig.json` should include:
```json
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node"
}
}
```
### Starting and Stopping a Simple Thread
`ThreadSimple` class allows you to manage subprocesses effectively. Here's how to start and stop a simple thread:
```typescript
// Import the necessary components from the library
import { ThreadSimple } from '@push.rocks/smartspawn';
// Define a function that creates, starts, and stops a thread
async function demonstrateThreadSimple() {
// Create an instance of ThreadSimple
const mySimpleThread = new ThreadSimple('./path/to/worker.js');
// Start the thread
await mySimpleThread.start();
console.log('Thread has started.');
// Stop the thread
await mySimpleThread.stop();
console.log('Thread has stopped.');
}
// Call the function to demonstrate its functionality
demonstrateThreadSimple();
```
The `./path/to/worker.js` should be the path to your worker script that you want to execute in a separate process.
### Wrapping Processes
`smartspawn` also provides functionality to wrap subprocesses, allowing you to modify or set up an environment before execution. Here's how to wrap and unwrap subprocesses:
```typescript
import { startSpawnWrap, endSpawnWrap } from '@push.rocks/smartspawn';
// Start a wrap
startSpawnWrap('path/to/script', ['arg1', 'arg2'], { ENV_VAR: 'value' });
console.log('Subprocess wrapped.');
// End the wrap when it's no longer needed
endSpawnWrap();
console.log('Subprocess unwrapped.');
```
### Advanced Thread Management
`@push.rocks/smartspawn` integrates with the `threads` package to provide advanced threading capabilities. Here's a brief example showing how you might utilize it for more complex scenarios:
```typescript
import { Thread, spawn, Worker } from 'threads';
async function advancedThreadExample() {
const thread = await spawn(new Worker('./worker'));
const result = await thread.doWork();
console.log(`Result from thread: ${result}`);
await Thread.terminate(thread);
}
advancedThreadExample();
```
Ensure you explore the `threads` documentation for a more detailed understanding of creating workers and communicating between the main process and threads.
### Conclusion
The `@push.rocks/smartspawn` package simplifies managing subprocesses in your Node.js applications, offering straightforward APIs for starting, stopping, and communicating with child processes. Whether you need to execute a simple script in the background or leverage sophisticated multi-threading capabilities, `smartspawn` provides the tools necessary to implement these features efficiently and robustly.
Remember, the examples above are starting points. Review the source code, tests, and type declarations for a comprehensive understanding of everything `@push.rocks/smartspawn` and its integrated packages can do. Experiment with the library in your projects to best learn how to utilize its full potential in real-world applications.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,61 +1,7 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@push.rocks/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;
tap.test('should create a simple test function', async () => {});
/**
* 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('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('child.ts');
});
tap.test('should run in a Pool', async () => {
let testPool = new smartspawn.Pool();
let testThread = new smartspawn.Thread('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('child.ts');
const message = await testThread.sendOnce('what');
expect(message).to.equal('what');
});
tap.start();
export default tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartspawn',
version: '3.0.3',
description: 'A node module for smart subprocess handling with support for promises and streamlined subprocess communication.'
}

View File

@ -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';

View File

@ -1,6 +0,0 @@
// ==============
// This file handles clustering of nodejs programs
// ==============
import * as plugins from './smartspawn.plugins';
export class Cluster {}

View File

@ -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);
}
}

View File

@ -1,85 +0,0 @@
import * as plugins from './smartspawn.plugins';
import * as paths from './smartspawn.paths';
import * as q from 'smartq';
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 = q.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 = q.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);
}
}
}

View File

@ -1,34 +0,0 @@
import 'typings-global';
import * as plugins from './smartspawn.plugins';
import * as q from 'smartq';
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 = q.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();
}
}

View File

@ -1,14 +1,12 @@
import * as plugins from './smartspawn.plugins';
import * as smartq from 'smartq';
import * as plugins from './smartspawn.plugins.js';
import * as smartpromise from '@push.rocks/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 = smartq.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();
}
}

View File

@ -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');
export const typescriptwrapJs = plugins.path.join(packageBase, 'assets/typescriptwrap.js');

View File

@ -1,5 +1,5 @@
import * as path from 'path';
let threads = require('threads');
import * as smartpromise from '@pushrocks/smartpromise';
import * as threads from 'threads';
import * as smartpromise from '@push.rocks/smartpromise';
export { path, smartpromise, threads };

View File

@ -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);

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}