Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 179 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"import": "./main.js",
"require": "./build/main.cjs"
},
"browser": "./build/main.ses.cjs",
"scripts": {
"test": "mocha",
"build": "rollup -c rollup.cjs.config.js"
"build": "rollup -c rollup.cjs.config.js",
"buildses": "SES=true rollup -c rollup.ses.config.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -42,6 +44,7 @@
"chai": "^4.2.0",
"eslint": "^8.0.1",
"mocha": "^8.2.1",
"rollup": "^2.38.5"
"rollup": "^2.38.5",
"rollup-plugin-jscc": "^2.0.0"
}
}
18 changes: 18 additions & 0 deletions rollup.ses.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import config from "./rollup.cjs.config.js";
import jscc from 'rollup-plugin-jscc'

export default {
input: "main.js",
output: {
file: "build/main.ses.cjs",
format: "cjs",
},
external: [
...config.external,
],
plugins: [
jscc({
values: { _SES: process.env.SES },
})
],
};
13 changes: 12 additions & 1 deletion src/threadman.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const MEM_SIZE = 25; // Memory size in 64K Pakes (1600Kb)

import thread from "./threadman_thread.js";
import os from "os";

/*#if _SES
//#else */
import Worker from "web-worker";
//#endif

class Deferred {
constructor() {
Expand All @@ -40,7 +44,7 @@ function sleep(ms) {
}

function stringToBase64(str) {
if (process.browser) {
if (process.browser && typeof globalThis.btoa === "function") {
return globalThis.btoa(str);
} else {
return Buffer.from(str).toString("base64");
Expand Down Expand Up @@ -81,7 +85,10 @@ export default async function buildThreadManager(wasm, singleThread) {
// tm.pTmp1 = tm.alloc(curve.G2.F.n8*3);


/*#if _SES
//#else */
if (singleThread) {
//#endif
tm.code = wasm.code;
tm.taskManager = thread();
await tm.taskManager([{
Expand All @@ -90,6 +97,8 @@ export default async function buildThreadManager(wasm, singleThread) {
code: tm.code.slice()
}]);
tm.concurrency = 1;
/*#if _SES
//#else */
} else {
tm.workers = [];
tm.pendingDeferreds = [];
Expand Down Expand Up @@ -133,6 +142,8 @@ export default async function buildThreadManager(wasm, singleThread) {
await Promise.all(initPromises);

}
//#endif

return tm;

function getOnMsg(i) {
Expand Down