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 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).