From 53b12f0c7bf0df695c9640adccead3c9142552d5 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 9 Jul 2020 16:31:41 -0700 Subject: [PATCH] quic: implement QuicEndpoint Promise API This is the start of a conversion over to a fully Promise-centric API for the QUIC implementation. PR-URL: https://github.com/nodejs/node/pull/34283 Reviewed-By: Anna Henningsen --- doc/api/quic.md | 42 +++++ lib/internal/quic/core.js | 160 ++++++++++++++++-- .../test-quic-quicendpoint-address.js | 18 +- 3 files changed, 200 insertions(+), 20 deletions(-) diff --git a/doc/api/quic.md b/doc/api/quic.md index 46f521789ef799..dee7f65f55cd49 100644 --- a/doc/api/quic.md +++ b/doc/api/quic.md @@ -338,6 +338,34 @@ The object will contain the properties: If the `QuicEndpoint` is not bound, `quicendpoint.address` is an empty object. +#### quicendpoint.bind(\[options\]) + + +Binds the `QuicEndpoint` if it has not already been bound. User code will +not typically be responsible for binding a `QuicEndpoint` as the owning +`QuicSocket` will do that automatically. + +* `options` {object} + * `signal` {AbortSignal} Optionally allows the `bind()` to be canceled + using an `AbortController`. +* Returns: {Promise} + +The `quicendpoint.bind()` function returns `Promise` that will be resolved +with the address once the bind operation is successful. + +If the `QuicEndpoint` has been destroyed, or is destroyed while the `Promise` +is pending, the `Promise` will be rejected with an `ERR_INVALID_STATE` error. + +If an `AbortSignal` is specified in the `options` and it is triggered while +the `Promise` is pending, the `Promise` will be rejected with an `AbortError`. + +If `quicendpoint.bind()` is called again while a previously returned `Promise` +is still pending or has already successfully resolved, the previously returned +pending `Promise` will be returned. If the additional call to +`quicendpoint.bind()` contains an `AbortSignal`, the `signal` will be ignored. + #### quicendpoint.bound + +Closes and destroys the `QuicEndpoint`. Returns a `Promise` that is resolved +once the `QuicEndpoint` has been destroyed, or rejects if the `QuicEndpoint` +is destroyed with an error. + +* Returns: {Promise} + +The `Promise` cannot be canceled. Once `quicendpoint.close()` is called, the +`QuicEndpoint` will be destroyed. + #### quicendpoint.closing