Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: make port transferables unique
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Nov 24, 2020
1 parent 75dd865 commit 6693663
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/ipfs-message-port-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ values instead of copying.

> **Note:** Transferring data will empty it on the sender side which can lead to
> errors if that data is used again later. To avoid these errors transfer option
> was added so user can explicitily give up reference when it is safe to do so.
> was added so user can explicitly give up reference when it is safe to do so.
```js
/**
Expand All @@ -115,7 +115,7 @@ const example = async (data) => {
}
```

It is however recommended to prefer web native [Blob][] / [File][] intances as
It is however recommended to prefer web native [Blob][] / [File][] instances as
most web APIs provide them as option & can be send across without copying
underlying memory.

Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-message-port-client/src/client/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = class MessageTransport {
input: query.toJSON()
},
// @ts-ignore - TS seems to want second arg to postMessage to not be undefined
query.transfer()
[...new Set(query.transfer() || [])]
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-message-port-protocol/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const decodeCallback = ({ port }) => {
* @returns {void}
*/
const callback = (args, transfer = []) => {
port.postMessage(args, transfer)
port.postMessage(args, [...new Set(transfer)])
}

return callback
Expand Down
5 changes: 4 additions & 1 deletion packages/ipfs-message-port-server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ exports.Server = class Server {
if (!query.signal.aborted) {
try {
const value = await query.result
const transfer = [...new Set(value.transfer || [])]
delete value.transfer

port.postMessage(
{ type: 'result', id, result: { ok: true, value } },
value.transfer || []
transfer
)
} catch (error) {
port.postMessage({
Expand Down

0 comments on commit 6693663

Please sign in to comment.