BREAKING CHANGE(package): change scope

This commit is contained in:
2018-08-02 15:31:05 +02:00
parent 18dfa70d16
commit fb2b72a97f
38 changed files with 1330 additions and 901 deletions

View File

@ -1,5 +1,3 @@
import 'typings-global'
import 'smartq'
module.exports = (input, done) => {
done(input)
}
done(input);
};

View File

@ -1,60 +1,61 @@
import { expect, tap } from 'tapbundle'
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartipc from '../ts/index'
import * as smartspawn from '../ts/index';
let testThreadFunction: smartipc.ThreadFunction
let testThread: smartipc.Thread
let testPool: smartipc.Pool
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 smartipc.ThreadFunction((input, done) => {
let url = require('url')
done(url.parse(input))
})
const message = await testThreadFunction.send('https://google.com')
console.log(message)
testThreadFunction.kill()
})
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 () => {
smartipc.setWorkerBasePath(__dirname)
testThread = new smartipc.Thread('child.js')
const message = await testThread.send('https://google.com')
console.log(message)
testThread.kill()
})
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 () => {
smartipc.setWorkerBasePath(__dirname)
let testThread = new smartipc.Thread('child.js')
})
smartspawn.setWorkerBasePath(__dirname);
let testThread = new smartspawn.Thread('child.ts');
});
tap.test('should run in a Pool', async () => {
let testPool = new smartipc.Pool()
let testThread = new smartipc.Thread('child.js')
testThread.assignToPool(testPool)
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)
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)
message = await testThread.send('another');
expect(message).to.equal('another');
console.log(message);
// kill all
testThread.assignedPool.pool.killAll()
})
testThread.assignedPool.pool.killAll();
});
tap.test('should once', async () => {
let testThread = new smartipc.Thread('child.js')
const message = await testThread.sendOnce('what')
expect(message).to.equal('what')
})
let testThread = new smartspawn.Thread('child.ts');
const message = await testThread.sendOnce('what');
expect(message).to.equal('what');
});
tap.start()
tap.start();