Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #26 - Avoid notifying unassigned SharedArrayBuffer entry #27

Merged
merged 2 commits into from
Oct 10, 2023
Merged
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
2 changes: 1 addition & 1 deletion esm/channel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ⚠️ AUTOMATICALLY GENERATED - DO NOT CHANGE
export const CHANNEL = '004aa280-89ed-4d6d-ba35-756aa263a436';
export const CHANNEL = '8db0a6b1-4d79-4ecd-8b7a-7ea5c1811764';

export const MAIN = 'M' + CHANNEL;
export const THREAD = 'T' + CHANNEL;
6 changes: 4 additions & 2 deletions esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const coincident = (self, {parse = JSON.parse, stringify = JSON.stringify, trans
const length = sb[0];

// filter undefined results
if (!length) return;
if (length < 0) return;

// calculate the needed ui16 bytes length to store the result string
const bytes = UI16_BYTES * length;
Expand Down Expand Up @@ -146,7 +146,9 @@ const coincident = (self, {parse = JSON.parse, stringify = JSON.stringify, trans
try {
// await for result either sync or async and serialize it
const result = await actions.get(action)(...args);
if (result !== void 0) {
if (result === void 0)
sb[0] = -1; // @see https://github.com/WebReflection/coincident/issues/26
else {
const serialized = stringify(transform ? transform(result) : result);
// store the result for "the very next" event listener call
results.set(id, serialized);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coincident",
"version": "0.13.4",
"version": "0.13.5",
"description": "An Atomics based Proxy to simplify, and synchronize, Worker related tasks",
"main": "./cjs/index.js",
"types": "./types/index.d.ts",
Expand Down
18 changes: 18 additions & 0 deletions test/issue-26/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module">
console.log('main');
import coincident from '../../es.js';
const proxy = coincident(new Worker('./worker.js', {type: 'module'}));
let func_calls = 0;
proxy.func = () => {
func_calls++;
if (func_calls % 1000 == 0)
console.log(`func: ${func_calls}`);
}
</script>
</head>
</html>
9 changes: 9 additions & 0 deletions test/issue-26/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
console.log('worker.js');

import coincident from '../../es.js';
const proxy = coincident(self);

(async () => {
for (let i = 0; i < 100000; i++)
proxy.func();
})();
Loading