Skip to content

Commit

Permalink
use named parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosSacASac committed Jul 15, 2019
1 parent 90517b1 commit f792482
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 98 deletions.
2 changes: 1 addition & 1 deletion example-deno/file_usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ registerWorker({
loadMode: FILE
});

work(`sort`, [1, 2, 3, -8, -5, 2, 3, 45, 5]).then(function (result) {
work({ name: `sort`, input: [1, 2, 3, -8, -5, 2, 3, 45, 5] }).then(function (result) {
console.log(result);
console.log(`after success`);
}).catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion example-node/file_usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ registerWorker({
loadMode: FILE
});

work(`sort`, [1, 2, 3, -8, -5, 2, 3, 45, 5]).then(function (result) {
work({ name: `sort`, input: [1, 2, 3, -8, -5, 2, 3, 45, 5] }).then(function (result) {
console.log(result);
console.log(`after success`);
}).catch(error => {
Expand Down
48 changes: 24 additions & 24 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
import estimatePi from "./estimatePi.js";
import { estimatePiWorkerURL } from "./estimatePiPrepared.js";

const ESTIMATEPI_RAW_WORKER_URL = "estimatePiWorker.js";
const ESTIMATEPI_RAW_WORKER_URL_NO_CACHE = "estimatePiWorkerNoCache.js";
const ESTIMATE_PI_ACTION = "estimatePi";
const ESTIMATEPI_RAW_WORKER_URL = `estimatePiWorker.js`;
const ESTIMATEPI_RAW_WORKER_URL_NO_CACHE = `estimatePiWorkerNoCache.js`;
const ESTIMATE_PI_ACTION = `estimatePi`;
const SAMPLE_SIZE = 10;
const INITIAL_PRECISION_LEVEL = 2 || 5;

Expand All @@ -39,13 +39,13 @@ let precision = precisionFromPrecisionLevel(INITIAL_PRECISION_LEVEL);


registerWorker({
name: "getPiEstimation",
name: `getPiEstimation`,
resource: estimatePi,
loadMode: FUNCTION
});

registerWorker({
name: "getPiEstimationForceRestart",
name: `getPiEstimationForceRestart`,
resource: estimatePi,
loadMode: FUNCTION,
hope: 5
Expand All @@ -54,16 +54,16 @@ registerWorker({


d.functions.setPrecision = function () {
precision = precisionFromPrecisionLevel(Number(d.variables["precisionLevel"]));
precision = precisionFromPrecisionLevel(Number(d.variables[`precisionLevel`]));
};

d.functions.webWorkerPreloaded = function () {
const startTime = getReferenceTime();

const worker = new Worker(estimatePiWorkerURL);
worker.addEventListener("message", function (event) {
worker.addEventListener(`message`, function (event) {
const message = event.data;
if (message.hasOwnProperty("result")) {
if (message.hasOwnProperty(`result`)) {
const result = message.result;
const endTime = getReferenceTime();
const duration = endTime - startTime;
Expand All @@ -86,9 +86,9 @@ d.functions.webWorkerNoCache = function () {
const startTime = getReferenceTime();

const worker = new Worker(ESTIMATEPI_RAW_WORKER_URL_NO_CACHE);
worker.addEventListener("message", function (event) {
worker.addEventListener(`message`, function (event) {
const message = event.data;
if (message.hasOwnProperty("result")) {
if (message.hasOwnProperty(`result`)) {

const result = message.result;
const endTime = getReferenceTime();
Expand All @@ -112,9 +112,9 @@ d.functions.webWorkerWithCache = function () {
const startTime = getReferenceTime();

const worker = new Worker(ESTIMATEPI_RAW_WORKER_URL);
worker.addEventListener("message", function (event) {
worker.addEventListener(`message`, function (event) {
const message = event.data;
if (message.hasOwnProperty("result")) {
if (message.hasOwnProperty(`result`)) {

const result = message.result;
const endTime = getReferenceTime();
Expand Down Expand Up @@ -188,7 +188,7 @@ const addAggregatesStats = function (aggregates) {

const testWithoutWorker = function () {
const aggregates = {
title: "Without Web Worker",
title: `Without Web Worker`,
totalComputationTime: 0,
meanTime: 0,
totalTime: 0,
Expand Down Expand Up @@ -219,7 +219,7 @@ const testWithoutWorker = function () {

const testWithRemoteServer = function () {
const aggregates = {
title: "With Remote Server",
title: `With Remote Server`,
totalComputationTime: 0,
meanTime: 0,
totalTime: 0,
Expand Down Expand Up @@ -258,7 +258,7 @@ const testWithRemoteServer = function () {

const testWithRawWorker = function () {
const aggregates = {
title: "With Raw Web Worker",
title: `With Raw Web Worker`,
totalComputationTime: 0,
meanTime: 0,
totalTime: 0,
Expand All @@ -271,9 +271,9 @@ const testWithRawWorker = function () {
return new Promise(function (resolve, reject) {
const startTime = getReferenceTime();
const worker = new Worker(ESTIMATEPI_RAW_WORKER_URL);
worker.addEventListener("message", function (event) {
worker.addEventListener(`message`, function (event) {
const message = event.data;
if (message.hasOwnProperty("result")) {
if (message.hasOwnProperty(`result`)) {
const piEstimation = message.result;
const endTime = getReferenceTime();
const duration = endTime - startTime;
Expand Down Expand Up @@ -307,7 +307,7 @@ const testWithRawWorker = function () {

const testWithWorkerCreatedEveryTime = function () {
const aggregates = {
title: "With Web Worker Created every time (worka)",
title: `With Web Worker Created every time (worka)`,
totalComputationTime: 0,
meanTime: 0,
totalTime: 0,
Expand All @@ -318,7 +318,7 @@ const testWithWorkerCreatedEveryTime = function () {

const workerWork = function () {
return timePromise(function () {
return work("getPiEstimationForceRestart", precision).catch(console.error);
return work({ name: `getPiEstimationForceRestart`, input: precision }).catch(console.error);
}).then(function ({ timeElapsed, value }) {
aggregates.totalComputationTime += timeElapsed;
return {
Expand All @@ -341,7 +341,7 @@ const testWithWorkerCreatedEveryTime = function () {

const testWithWorker = function () {
const aggregates = {
title: "With Web Worker (worka)",
title: `With Web Worker (worka)`,
totalComputationTime: 0,
meanTime: 0,
totalTime: 0,
Expand All @@ -352,13 +352,13 @@ const testWithWorker = function () {

const workerWork = function () {
return timePromise(function () {
return work("getPiEstimation", precision).catch(console.error);
return work({ name: `getPiEstimation`, input: precision }).catch(console.error);
}).then(function ({ timeElapsed, value }) {
aggregates.totalComputationTime += timeElapsed;
return {
precision,
duration: timeElapsed,
piEstimation: value
piEstimation: value,
};
});
};
Expand All @@ -375,7 +375,7 @@ const testWithWorker = function () {

const testWithWorkerAutoSplit = function () {
const aggregates = {
title: "With Web Worker auto split (worka)",
title: `With Web Worker auto split (worka)`,
totalComputationTime: 0,
meanTime: 0,
totalTime: 0,
Expand All @@ -386,7 +386,7 @@ const testWithWorkerAutoSplit = function () {

const workerWork = function () {
return timePromise(function () {
return work("getPiEstimation", precision).catch(console.error);
return work({ name: `getPiEstimation`, input: precision }).catch(console.error);
}).then(function ({ timeElapsed, value }) {
aggregates.totalComputationTime += timeElapsed;
return {
Expand Down
6 changes: 3 additions & 3 deletions example/worka.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
};

registerWorker({
name: "sort",
name: `sort`,
resource: sort,
loadMode: FUNCTION
});

work("sort", [1, 2, 3, -8, -5, 2, 3, 45, 5]).then(function (result) {
work({name: `sort`, input: [1, 2, 3, -8, -5, 2, 3, 45, 5]}).then(function (result) {
console.log(result);
console.log("after success");
console.log(`after success`);
});

</script>
Expand Down
8 changes: 4 additions & 4 deletions example/workaRunTimeError.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
};

registerWorker({
name: "sort",
name: `sort`,
resource: sort,
loadMode: FUNCTION
});

work("sort", [1, 2, 3, -8, -5, 2, 3, 45, 5]).then(function (result) {
work({name: `sort`, input: [1, 2, 3, -8, -5, 2, 3, 45, 5]}).then(function (result) {
console.log(result);
console.log("after success");
console.log(`after success`);
}).catch(function (error) {
console.log("in the catch");
console.log(`in the catch`);
console.error(error);
});

Expand Down
4 changes: 1 addition & 3 deletions example/workaSyntaxError.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
return array;
}`;

console.log("1");
registerWorker({
name: "sort",
resource: sort,
loadMode: STRING
});

console.log("2");
work("sort", [1, 2, 3, -8, -5, 2, 3, 45, 5]).then(function (result) {
work({name: `sort`, input: [1, 2, 3, -8, -5, 2, 3, 45, 5]}).then(function (result) {
console.log(result);
console.log("after success");
}).catch(function (error) {
Expand Down
Loading

0 comments on commit f792482

Please sign in to comment.