Primeiro commit do projeto Angular
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
import { resolve } from 'node:path';
|
||||
import Piscina from '../..';
|
||||
|
||||
const pool = new Piscina({
|
||||
filename: resolve(__dirname, 'eval.js'),
|
||||
maxThreads: 1,
|
||||
env: {
|
||||
PISCINA_ENABLE_ASYNC_ATOMICS: process.env.PISCINA_ENABLE_ASYNC_ATOMICS
|
||||
}
|
||||
});
|
||||
|
||||
pool.run('console.log("A"); console.error("B");');
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { promisify } from 'node:util';
|
||||
|
||||
const sleep = promisify(setTimeout);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
function handler (code) { return eval(code); }
|
||||
|
||||
async function load () {
|
||||
await sleep(5);
|
||||
return handler;
|
||||
}
|
||||
|
||||
export default load();
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// eslint-disable-next-line no-eval
|
||||
export default function (code) { return eval(code); };
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const { promisify } = require('node:util');
|
||||
|
||||
const sleep = promisify(setTimeout);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
function handler (code) { return eval(code); }
|
||||
|
||||
async function load () {
|
||||
await sleep(5);
|
||||
return handler;
|
||||
}
|
||||
|
||||
module.exports = load();
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// eslint-disable-next-line no-eval
|
||||
module.exports = function (input) { return eval(input.code); };
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// eslint-disable-next-line no-eval
|
||||
module.exports = function (code) { return eval(code); };
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import assert from 'node:assert';
|
||||
import { types } from 'node:util';
|
||||
import Piscina from '../..';
|
||||
|
||||
export default function (moved) {
|
||||
if (moved !== undefined) {
|
||||
assert(types.isAnyArrayBuffer(moved));
|
||||
}
|
||||
return Piscina.move(new ArrayBuffer(10));
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
function a () { return 'a'; }
|
||||
|
||||
function b () { return 'b'; }
|
||||
|
||||
a.a = a;
|
||||
a.b = b;
|
||||
|
||||
module.exports = a;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// Set the index-th bith in i32array[0], then wait for it to be un-set again.
|
||||
module.exports = function ({ i32array, index }) {
|
||||
Atomics.or(i32array, 0, 1 << index);
|
||||
Atomics.notify(i32array, 0, Infinity);
|
||||
do {
|
||||
const v = Atomics.load(i32array, 0);
|
||||
if (!(v & (1 << index))) break;
|
||||
Atomics.wait(i32array, 0, v);
|
||||
} while (true);
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// Set the index-th bith in i32array[0], then wait for it to be un-set again.
|
||||
module.exports = function ({ i32array, index }) {
|
||||
Atomics.or(i32array, 0, 1 << index);
|
||||
Atomics.notify(i32array, 0, Infinity);
|
||||
do {
|
||||
const v = Atomics.load(i32array, 0);
|
||||
if (!(v & (1 << index))) break;
|
||||
Atomics.wait(i32array, 0, v);
|
||||
} while (true);
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
module.exports = function (i32array) {
|
||||
Atomics.store(i32array, 0, 1);
|
||||
Atomics.notify(i32array, 0, Infinity);
|
||||
Atomics.wait(i32array, 0, 1);
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = () => {
|
||||
const array = [];
|
||||
while (true) {
|
||||
array.push([array]);
|
||||
}
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const Piscina = require('../../dist');
|
||||
|
||||
let time;
|
||||
module.exports = {
|
||||
send: async () => {
|
||||
const data = new ArrayBuffer(128);
|
||||
try {
|
||||
return Piscina.move(data);
|
||||
} finally {
|
||||
setTimeout(() => { time = data.byteLength; }, 5);
|
||||
}
|
||||
},
|
||||
get: () => {
|
||||
return time;
|
||||
}
|
||||
};
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const Piscina = require('../../dist');
|
||||
|
||||
class Shared {
|
||||
constructor (data) {
|
||||
this.name = 'shared';
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
get [Piscina.transferableSymbol] () {
|
||||
return [this.data];
|
||||
}
|
||||
|
||||
get [Piscina.valueSymbol] () {
|
||||
return { name: this.name, data: this.data };
|
||||
}
|
||||
|
||||
make () {
|
||||
return Piscina.move(this);
|
||||
}
|
||||
}
|
||||
|
||||
let time;
|
||||
module.exports = {
|
||||
send: async () => {
|
||||
const data = new ArrayBuffer(128);
|
||||
const shared = new Shared(data);
|
||||
try {
|
||||
return shared.make();
|
||||
} finally {
|
||||
setTimeout(() => { time = data.byteLength; }, 5);
|
||||
}
|
||||
},
|
||||
get: () => {
|
||||
return time;
|
||||
}
|
||||
};
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import assert from 'node:assert';
|
||||
import { isWorkerThread } from '../..';
|
||||
|
||||
assert.strictEqual(isWorkerThread, true);
|
||||
|
||||
export default function () { return 'done'; }
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import assert from 'node:assert';
|
||||
import Piscina from '../..';
|
||||
|
||||
assert.strictEqual(Piscina.isWorkerThread, true);
|
||||
|
||||
export default function () { return 'done'; }
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import assert from 'node:assert';
|
||||
import { workerData } from '../..';
|
||||
|
||||
assert.strictEqual(workerData, 'ABC');
|
||||
|
||||
export default function () { return 'done'; }
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import assert from 'node:assert';
|
||||
import Piscina from '../..';
|
||||
|
||||
assert.strictEqual(Piscina.workerData, 'ABC');
|
||||
|
||||
export default function () { return 'done'; }
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const { promisify } = require('node:util');
|
||||
|
||||
const sleep = promisify(setTimeout);
|
||||
|
||||
const buf = new Uint32Array(new SharedArrayBuffer(4));
|
||||
|
||||
module.exports = async ({ time = 5, a }) => {
|
||||
await sleep(time);
|
||||
const ret = Atomics.exchange(buf, 0, a);
|
||||
return ret;
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// worker.js
|
||||
const vm = require('node:vm');
|
||||
|
||||
module.exports = ({ payload, context }) => {
|
||||
const script = new vm.Script(payload);
|
||||
script.runInNewContext(context);
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
module.exports = function (i32array) {
|
||||
Atomics.wait(i32array, 0, 0);
|
||||
Atomics.store(i32array, 0, -1);
|
||||
Atomics.notify(i32array, 0, Infinity);
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
module.exports = function (i32array) {
|
||||
Atomics.wait(i32array, 0, 0);
|
||||
Atomics.store(i32array, 0, -1);
|
||||
Atomics.notify(i32array, 0, Infinity);
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { threadId } from 'worker_threads';
|
||||
|
||||
module.exports = async function ([i32array, n]) {
|
||||
Atomics.add(i32array, 0, 1);
|
||||
Atomics.notify(i32array, 0, Infinity);
|
||||
let lastSeenValue;
|
||||
while ((lastSeenValue = Atomics.load(i32array, 0)) < n) {
|
||||
Atomics.wait(i32array, 0, lastSeenValue);
|
||||
}
|
||||
return threadId;
|
||||
};
|
||||
Reference in New Issue
Block a user