Skip to content

Commit d33bc66

Browse files
committed
v0.5.14
1 parent 7507832 commit d33bc66

24 files changed

+97
-81
lines changed

CHANGE.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.5.14
2+
3+
- concurrent.module is renamed to concurrent.import.
4+
15
## v0.5.13
26

37
- Unit tests are implemented for some of the platform core classes.

apps/sample/browser/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { concurrent } from '@bitair/concurrent.js'
33
import type * as Services from './services/index.js'
44

55
const main = async () => {
6-
const { factorial } = await concurrent.module<typeof Services>('./services/index.js').load()
6+
const { factorial } = await concurrent.import<typeof Services>('./services/index.js').load()
77

88
const progress = setInterval(() => console.log('⯀'), 100) // Using this to show that the main thread is not blocked
99

apps/sample/deno/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { concurrent } from '../../../../mod.ts'
22

3-
const { factorial } = await concurrent.module(new URL('./services/index.ts', import.meta.url)).load()
3+
const { factorial } = await concurrent.import(new URL('./services/index.ts', import.meta.url)).load()
44

55
const progress = setInterval(() => console.log('⯀'), 100)
66

apps/sample/node/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { concurrent } from '@bitair/concurrent.js'
33
import type * as ExtraBigIntModule from 'extra-bigint'
44

55
async function main() {
6-
const { factorial } = await concurrent.module<typeof ExtraBigIntModule>('extra-bigint').load()
6+
const { factorial } = await concurrent.import<typeof ExtraBigIntModule>('extra-bigint').load()
77

88
const progress = setInterval(() => process.stdout.write('⯀'), 100) // Using this to show that the main thread is not blocked
99

apps/sample/node/test/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let Math: typeof MathModule
66

77
describe('Testing Node Sample', () => {
88
before(async () => {
9-
Math = await concurrent.module<typeof MathModule>('extra-bigint').load()
9+
Math = await concurrent.import<typeof MathModule>('extra-bigint').load()
1010
})
1111

1212
after(async () => {

dist/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "module",
33
"name": "@bitair/concurrent.js",
4-
"version": "0.5.13",
4+
"version": "0.5.14",
55
"description": "Easy Multithreading for JavaScript (Node.js, Deno & Browser)",
66
"main": "src/node/index.js",
77
"browser": "src/browser/index.js",

dist/src/browser/index.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var ErrorMessage = {
4646
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
4747
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
4848
MethodAssignment: { code: 509, text: "Can't assign a method." },
49-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
49+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
5050
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
5151
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
5252
};
@@ -245,22 +245,22 @@ var ConcurrentModule = class {
245245
const thread = await this.pool.getThread();
246246
const cache = {};
247247
return new Proxy(module, {
248-
get(module2, exportName) {
249-
const _export = Reflect.get(module2, exportName);
250-
if (!Reflect.has(module2, exportName))
248+
get(obj, key) {
249+
const _export = Reflect.get(obj, key);
250+
if (!Reflect.has(obj, key))
251251
return;
252252
else if (!isFunction(_export))
253-
throw new ConcurrencyError(ErrorMessage.NonFunctionLoad);
253+
throw new ConcurrencyError(ErrorMessage.NotAccessibleExport);
254254
else {
255-
if (!Reflect.has(cache, exportName))
256-
Reflect.set(cache, exportName, createFunctionProxy(thread, moduleSrc, _export));
257-
return Reflect.get(cache, exportName);
255+
if (!Reflect.has(cache, key))
256+
Reflect.set(cache, key, createThreadedFunction(thread, moduleSrc, _export));
257+
return Reflect.get(cache, key);
258258
}
259259
}
260260
});
261261
}
262262
};
263-
function createFunctionProxy(thread, moduleSrc, target) {
263+
function createThreadedFunction(thread, moduleSrc, target) {
264264
const threadedFunction = new ThreadedFunction(thread, moduleSrc, target.name);
265265
return new Proxy(target, {
266266
get(target2, key) {
@@ -291,14 +291,14 @@ function createFunctionProxy(thread, moduleSrc, target) {
291291
}
292292
},
293293
construct(target2, args) {
294-
return createObjectProxy(thread, moduleSrc, target2.name, args);
294+
return createThreadedObject(thread, moduleSrc, target2.name, args);
295295
},
296296
apply(_target, _thisArg, args) {
297297
return threadedFunction.invoke(args);
298298
}
299299
});
300300
}
301-
async function createObjectProxy(thread, moduleSrc, exportName, args) {
301+
async function createThreadedObject(thread, moduleSrc, exportName, args) {
302302
const threadedObject = await ThreadedObject.create(thread, moduleSrc, exportName, args);
303303
return new Proxy(threadedObject.target, {
304304
get(target, key) {
@@ -482,7 +482,7 @@ var Master = class {
482482
if (this.started)
483483
this.pool.config(this.settings);
484484
}
485-
module(moduleSrc) {
485+
import(moduleSrc) {
486486
if (!this.settings.disabled && !this.started)
487487
this.start();
488488
const module = this.settings.disabled ? {

dist/src/browser/worker_script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var ErrorMessage = {
2828
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
2929
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
3030
MethodAssignment: { code: 509, text: "Can't assign a method." },
31-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
31+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
3232
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
3333
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
3434
};

dist/src/deno/index.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var ErrorMessage = {
6565
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
6666
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
6767
MethodAssignment: { code: 509, text: "Can't assign a method." },
68-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
68+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
6969
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
7070
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
7171
};
@@ -254,22 +254,22 @@ var ConcurrentModule = class {
254254
const thread = await this.pool.getThread();
255255
const cache = {};
256256
return new Proxy(module, {
257-
get(module2, exportName) {
258-
const _export = Reflect.get(module2, exportName);
259-
if (!Reflect.has(module2, exportName))
257+
get(obj, key) {
258+
const _export = Reflect.get(obj, key);
259+
if (!Reflect.has(obj, key))
260260
return;
261261
else if (!isFunction(_export))
262-
throw new ConcurrencyError(ErrorMessage.NonFunctionLoad);
262+
throw new ConcurrencyError(ErrorMessage.NotAccessibleExport);
263263
else {
264-
if (!Reflect.has(cache, exportName))
265-
Reflect.set(cache, exportName, createFunctionProxy(thread, moduleSrc, _export));
266-
return Reflect.get(cache, exportName);
264+
if (!Reflect.has(cache, key))
265+
Reflect.set(cache, key, createThreadedFunction(thread, moduleSrc, _export));
266+
return Reflect.get(cache, key);
267267
}
268268
}
269269
});
270270
}
271271
};
272-
function createFunctionProxy(thread, moduleSrc, target) {
272+
function createThreadedFunction(thread, moduleSrc, target) {
273273
const threadedFunction = new ThreadedFunction(thread, moduleSrc, target.name);
274274
return new Proxy(target, {
275275
get(target2, key) {
@@ -300,14 +300,14 @@ function createFunctionProxy(thread, moduleSrc, target) {
300300
}
301301
},
302302
construct(target2, args) {
303-
return createObjectProxy(thread, moduleSrc, target2.name, args);
303+
return createThreadedObject(thread, moduleSrc, target2.name, args);
304304
},
305305
apply(_target, _thisArg, args) {
306306
return threadedFunction.invoke(args);
307307
}
308308
});
309309
}
310-
async function createObjectProxy(thread, moduleSrc, exportName, args) {
310+
async function createThreadedObject(thread, moduleSrc, exportName, args) {
311311
const threadedObject = await ThreadedObject.create(thread, moduleSrc, exportName, args);
312312
return new Proxy(threadedObject.target, {
313313
get(target, key) {
@@ -491,7 +491,7 @@ var Master = class {
491491
if (this.started)
492492
this.pool.config(this.settings);
493493
}
494-
module(moduleSrc) {
494+
import(moduleSrc) {
495495
if (!this.settings.disabled && !this.started)
496496
this.start();
497497
const module = this.settings.disabled ? {

dist/src/deno/worker_script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var ErrorMessage = {
2828
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
2929
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
3030
MethodAssignment: { code: 509, text: "Can't assign a method." },
31-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
31+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
3232
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
3333
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
3434
};

dist/src/index.d.cts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { concurrent }
33

44
export declare interface IConcurrent {
55
config(settings: Partial<ConcurrencySettings>): void
6-
module<T>(moduleSrc: string | URL): IConcurrentModule<T>
6+
import<T>(moduleSrc: string | URL): IConcurrentModule<T>
77
terminate(force?: boolean): Promise<void>
88
}
99

dist/src/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { concurrent }
33

44
export declare interface IConcurrent {
55
config(settings: Partial<ConcurrencySettings>): void
6-
module<T>(moduleSrc: string | URL): IConcurrentModule<T>
6+
import<T>(moduleSrc: string | URL): IConcurrentModule<T>
77
terminate(force?: boolean): Promise<void>
88
}
99

dist/src/node/index.cjs

+12-12
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var ErrorMessage = {
9292
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
9393
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
9494
MethodAssignment: { code: 509, text: "Can't assign a method." },
95-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
95+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
9696
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
9797
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
9898
};
@@ -281,22 +281,22 @@ var ConcurrentModule = class {
281281
const thread = await this.pool.getThread();
282282
const cache = {};
283283
return new Proxy(module2, {
284-
get(module3, exportName) {
285-
const _export = Reflect.get(module3, exportName);
286-
if (!Reflect.has(module3, exportName))
284+
get(obj, key) {
285+
const _export = Reflect.get(obj, key);
286+
if (!Reflect.has(obj, key))
287287
return;
288288
else if (!isFunction(_export))
289-
throw new ConcurrencyError(ErrorMessage.NonFunctionLoad);
289+
throw new ConcurrencyError(ErrorMessage.NotAccessibleExport);
290290
else {
291-
if (!Reflect.has(cache, exportName))
292-
Reflect.set(cache, exportName, createFunctionProxy(thread, moduleSrc, _export));
293-
return Reflect.get(cache, exportName);
291+
if (!Reflect.has(cache, key))
292+
Reflect.set(cache, key, createThreadedFunction(thread, moduleSrc, _export));
293+
return Reflect.get(cache, key);
294294
}
295295
}
296296
});
297297
}
298298
};
299-
function createFunctionProxy(thread, moduleSrc, target) {
299+
function createThreadedFunction(thread, moduleSrc, target) {
300300
const threadedFunction = new ThreadedFunction(thread, moduleSrc, target.name);
301301
return new Proxy(target, {
302302
get(target2, key) {
@@ -327,14 +327,14 @@ function createFunctionProxy(thread, moduleSrc, target) {
327327
}
328328
},
329329
construct(target2, args) {
330-
return createObjectProxy(thread, moduleSrc, target2.name, args);
330+
return createThreadedObject(thread, moduleSrc, target2.name, args);
331331
},
332332
apply(_target, _thisArg, args) {
333333
return threadedFunction.invoke(args);
334334
}
335335
});
336336
}
337-
async function createObjectProxy(thread, moduleSrc, exportName, args) {
337+
async function createThreadedObject(thread, moduleSrc, exportName, args) {
338338
const threadedObject = await ThreadedObject.create(thread, moduleSrc, exportName, args);
339339
return new Proxy(threadedObject.target, {
340340
get(target, key) {
@@ -518,7 +518,7 @@ var Master = class {
518518
if (this.started)
519519
this.pool.config(this.settings);
520520
}
521-
module(moduleSrc) {
521+
import(moduleSrc) {
522522
if (!this.settings.disabled && !this.started)
523523
this.start();
524524
const module2 = this.settings.disabled ? {

dist/src/node/index.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var ErrorMessage = {
6868
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
6969
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
7070
MethodAssignment: { code: 509, text: "Can't assign a method." },
71-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
71+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
7272
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
7373
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
7474
};
@@ -257,22 +257,22 @@ var ConcurrentModule = class {
257257
const thread = await this.pool.getThread();
258258
const cache = {};
259259
return new Proxy(module, {
260-
get(module2, exportName) {
261-
const _export = Reflect.get(module2, exportName);
262-
if (!Reflect.has(module2, exportName))
260+
get(obj, key) {
261+
const _export = Reflect.get(obj, key);
262+
if (!Reflect.has(obj, key))
263263
return;
264264
else if (!isFunction(_export))
265-
throw new ConcurrencyError(ErrorMessage.NonFunctionLoad);
265+
throw new ConcurrencyError(ErrorMessage.NotAccessibleExport);
266266
else {
267-
if (!Reflect.has(cache, exportName))
268-
Reflect.set(cache, exportName, createFunctionProxy(thread, moduleSrc, _export));
269-
return Reflect.get(cache, exportName);
267+
if (!Reflect.has(cache, key))
268+
Reflect.set(cache, key, createThreadedFunction(thread, moduleSrc, _export));
269+
return Reflect.get(cache, key);
270270
}
271271
}
272272
});
273273
}
274274
};
275-
function createFunctionProxy(thread, moduleSrc, target) {
275+
function createThreadedFunction(thread, moduleSrc, target) {
276276
const threadedFunction = new ThreadedFunction(thread, moduleSrc, target.name);
277277
return new Proxy(target, {
278278
get(target2, key) {
@@ -303,14 +303,14 @@ function createFunctionProxy(thread, moduleSrc, target) {
303303
}
304304
},
305305
construct(target2, args) {
306-
return createObjectProxy(thread, moduleSrc, target2.name, args);
306+
return createThreadedObject(thread, moduleSrc, target2.name, args);
307307
},
308308
apply(_target, _thisArg, args) {
309309
return threadedFunction.invoke(args);
310310
}
311311
});
312312
}
313-
async function createObjectProxy(thread, moduleSrc, exportName, args) {
313+
async function createThreadedObject(thread, moduleSrc, exportName, args) {
314314
const threadedObject = await ThreadedObject.create(thread, moduleSrc, exportName, args);
315315
return new Proxy(threadedObject.target, {
316316
get(target, key) {
@@ -494,7 +494,7 @@ var Master = class {
494494
if (this.started)
495495
this.pool.config(this.settings);
496496
}
497-
module(moduleSrc) {
497+
import(moduleSrc) {
498498
if (!this.settings.disabled && !this.started)
499499
this.start();
500500
const module = this.settings.disabled ? {

dist/src/node/worker_script.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var ErrorMessage = {
4747
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
4848
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
4949
MethodAssignment: { code: 509, text: "Can't assign a method." },
50-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
50+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
5151
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
5252
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
5353
};

dist/src/node/worker_script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var ErrorMessage = {
4646
WorkerNotSupported: { code: 507, text: "This browser doesn't support web workers." },
4747
ThreadAllocationTimeout: { code: 508, text: "Thread allocation failed due to timeout." },
4848
MethodAssignment: { code: 509, text: "Can't assign a method." },
49-
NonFunctionLoad: { code: 510, text: "Can't load an export of type '%{0}'." },
49+
NotAccessibleExport: { code: 510, text: "Can't access an export of type '%{0}'. Only top level functions and classes are imported." },
5050
ThreadPoolTerminated: { code: 511, text: "Thread pool has been terminated." },
5151
ThreadTerminated: { code: 512, text: "Thread has been terminated." }
5252
};

0 commit comments

Comments
 (0)