penpal 7.0.6 → 8.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -4
- package/dist/penpal.cjs +748 -963
- package/dist/penpal.cjs.map +1 -1
- package/dist/penpal.d.cts +180 -149
- package/dist/penpal.d.cts.map +1 -0
- package/dist/penpal.d.ts +180 -149
- package/dist/penpal.d.ts.map +1 -0
- package/dist/penpal.js +760 -977
- package/dist/penpal.js.map +1 -1
- package/dist/penpal.min.js +2 -1
- package/dist/penpal.min.js.map +1 -1
- package/dist/penpal.mjs +739 -953
- package/dist/penpal.mjs.map +1 -1
- package/package.json +56 -37
- package/src/CallOptions.ts +18 -0
- package/src/ErrorCodeObj.ts +13 -0
- package/src/PenpalError.ts +13 -0
- package/src/Reply.ts +23 -0
- package/src/connect.ts +157 -0
- package/src/connectCallHandler.ts +119 -0
- package/src/connectRemoteProxy.ts +199 -0
- package/src/debug.ts +9 -0
- package/src/errorSerialization.ts +31 -0
- package/src/generateId.ts +12 -0
- package/src/guards.ts +50 -0
- package/src/index.ts +27 -0
- package/src/messengers/Messenger.ts +18 -0
- package/src/messengers/PortMessenger.ts +68 -0
- package/src/messengers/WindowMessenger.ts +232 -0
- package/src/messengers/WorkerMessenger.ts +144 -0
- package/src/methodPath.ts +24 -0
- package/src/namespace.ts +1 -0
- package/src/once.ts +17 -0
- package/src/shakeHands.ts +270 -0
- package/src/types.ts +121 -0
package/README.md
CHANGED
|
@@ -354,7 +354,7 @@ const initPenpal = async () => {
|
|
|
354
354
|
},
|
|
355
355
|
{
|
|
356
356
|
transfer: [port2],
|
|
357
|
-
}
|
|
357
|
+
},
|
|
358
358
|
);
|
|
359
359
|
|
|
360
360
|
const messenger = new PortMessenger({
|
|
@@ -438,7 +438,25 @@ If you'd like to see running examples of the different types of usage, check out
|
|
|
438
438
|
|
|
439
439
|
## Destroying the Connection
|
|
440
440
|
|
|
441
|
-
At any point in time, call `connection.destroy()` to destroy the connection so that event listeners can be removed and objects can be properly garbage collected.
|
|
441
|
+
At any point in time, call `connection.destroy()` to destroy the connection so that event listeners can be removed and objects can be properly garbage collected. If the connection is destroyed before it has been established, the promise found at `connection.promise` will be rejected with a `CONNECTION_DESTROYED` error.
|
|
442
|
+
|
|
443
|
+
```javascript
|
|
444
|
+
import { connect, ErrorCode } from 'penpal';
|
|
445
|
+
|
|
446
|
+
const connection = connect({
|
|
447
|
+
messenger,
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
connection.destroy();
|
|
451
|
+
|
|
452
|
+
try {
|
|
453
|
+
await connection.promise;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
if (error.code === ErrorCode.ConnectionDestroyed) {
|
|
456
|
+
// Connection failed because it was destroyed.
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
```
|
|
442
460
|
|
|
443
461
|
## Debugging
|
|
444
462
|
|
|
@@ -664,7 +682,7 @@ Penpal will throw or reject promises with errors in certain situations. Each err
|
|
|
664
682
|
|
|
665
683
|
`CONNECTION_DESTROYED`
|
|
666
684
|
|
|
667
|
-
This error will be thrown when attempting to call a method and the connection was previously destroyed.
|
|
685
|
+
This error will be thrown when attempting to call a method and the connection was previously destroyed. The promise found at `connection.promise` will also be rejected with this error if the connection is destroyed before it has been established.
|
|
668
686
|
|
|
669
687
|
`CONNECTION_TIMEOUT`
|
|
670
688
|
|
|
@@ -805,7 +823,7 @@ A promise which will be resolved once communication has been established. The pr
|
|
|
805
823
|
|
|
806
824
|
`destroy: () => void`
|
|
807
825
|
|
|
808
|
-
A method that, when called, will disconnect any messaging channels, event listeners, etc. You may call this even before a connection has been established. See [Destroying the Connection](#destroying-the-connection) for more information.
|
|
826
|
+
A method that, when called, will disconnect any messaging channels, event listeners, etc. You may call this even before a connection has been established. If called before a connection has been established, the promise found at `connection.promise` will be rejected with a `CONNECTION_DESTROYED` error. See [Destroying the Connection](#destroying-the-connection) for more information.
|
|
809
827
|
|
|
810
828
|
---
|
|
811
829
|
|
|
@@ -872,3 +890,7 @@ This library is inspired by:
|
|
|
872
890
|
## License
|
|
873
891
|
|
|
874
892
|
MIT
|
|
893
|
+
|
|
894
|
+
## Contributing
|
|
895
|
+
|
|
896
|
+
If you'd like to contribute or run the full local test/build workflows, see [CONTRIBUTING.md](./CONTRIBUTING.md).
|