mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
feat: deprecate Deno.{Conn,TcpConn,TlsConn,UnixConn}.rid
(#22077)
For removal in Deno v2. Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
176118a046
commit
fc176c4dea
4 changed files with 96 additions and 17 deletions
|
@ -1,10 +1,10 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
itest!(workers {
|
||||
args: "test --reload --location http://127.0.0.1:4545/ -A --unstable workers/test.ts",
|
||||
output: "workers/test.ts.out",
|
||||
http_server: true,
|
||||
});
|
||||
args: "test --reload --location http://127.0.0.1:4545/ -A --unstable-worker-options workers/test.ts",
|
||||
output: "workers/test.ts.out",
|
||||
http_server: true,
|
||||
});
|
||||
|
||||
itest!(worker_error {
|
||||
args: "run -A workers/worker_error.ts",
|
||||
|
|
|
@ -106,6 +106,11 @@ class Conn {
|
|||
}
|
||||
|
||||
get rid() {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.Conn.rid",
|
||||
new Error().stack,
|
||||
"Use `Deno.Conn` instance methods instead.",
|
||||
);
|
||||
return this.#rid;
|
||||
}
|
||||
|
||||
|
@ -118,14 +123,14 @@ class Conn {
|
|||
}
|
||||
|
||||
write(p) {
|
||||
return write(this.rid, p);
|
||||
return write(this.#rid, p);
|
||||
}
|
||||
|
||||
async read(buffer) {
|
||||
if (buffer.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
const promise = core.read(this.rid, buffer);
|
||||
const promise = core.read(this.#rid, buffer);
|
||||
if (this.#unref) core.unrefOpPromise(promise);
|
||||
SetPrototypeAdd(this.#pendingReadPromises, promise);
|
||||
let nread;
|
||||
|
@ -140,16 +145,16 @@ class Conn {
|
|||
}
|
||||
|
||||
close() {
|
||||
core.close(this.rid);
|
||||
core.close(this.#rid);
|
||||
}
|
||||
|
||||
closeWrite() {
|
||||
return shutdown(this.rid);
|
||||
return shutdown(this.#rid);
|
||||
}
|
||||
|
||||
get readable() {
|
||||
if (this.#readable === undefined) {
|
||||
this.#readable = readableStreamForRidUnrefable(this.rid);
|
||||
this.#readable = readableStreamForRidUnrefable(this.#rid);
|
||||
if (this.#unref) {
|
||||
readableStreamForRidUnrefableUnref(this.#readable);
|
||||
}
|
||||
|
@ -159,7 +164,7 @@ class Conn {
|
|||
|
||||
get writable() {
|
||||
if (this.#writable === undefined) {
|
||||
this.#writable = writableStreamForRid(this.rid);
|
||||
this.#writable = writableStreamForRid(this.#rid);
|
||||
}
|
||||
return this.#writable;
|
||||
}
|
||||
|
@ -193,16 +198,48 @@ class Conn {
|
|||
}
|
||||
|
||||
class TcpConn extends Conn {
|
||||
#rid = 0;
|
||||
|
||||
constructor(rid, remoteAddr, localAddr) {
|
||||
super(rid, remoteAddr, localAddr);
|
||||
this.#rid = rid;
|
||||
}
|
||||
|
||||
get rid() {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.TcpConn.rid",
|
||||
new Error().stack,
|
||||
"Use `Deno.TcpConn` instance methods instead.",
|
||||
);
|
||||
return this.#rid;
|
||||
}
|
||||
|
||||
setNoDelay(noDelay = true) {
|
||||
return op_set_nodelay(this.rid, noDelay);
|
||||
return op_set_nodelay(this.#rid, noDelay);
|
||||
}
|
||||
|
||||
setKeepAlive(keepAlive = true) {
|
||||
return op_set_keepalive(this.rid, keepAlive);
|
||||
return op_set_keepalive(this.#rid, keepAlive);
|
||||
}
|
||||
}
|
||||
|
||||
class UnixConn extends Conn {}
|
||||
class UnixConn extends Conn {
|
||||
#rid = 0;
|
||||
|
||||
constructor(rid, remoteAddr, localAddr) {
|
||||
super(rid, remoteAddr, localAddr);
|
||||
this.#rid = rid;
|
||||
}
|
||||
|
||||
get rid() {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.UnixConn.rid",
|
||||
new Error().stack,
|
||||
"Use `Deno.UnixConn` instance methods instead.",
|
||||
);
|
||||
return this.#rid;
|
||||
}
|
||||
}
|
||||
|
||||
class Listener {
|
||||
#rid = 0;
|
||||
|
|
|
@ -24,8 +24,24 @@ function opTlsHandshake(rid) {
|
|||
}
|
||||
|
||||
class TlsConn extends Conn {
|
||||
#rid = 0;
|
||||
|
||||
constructor(rid, remoteAddr, localAddr) {
|
||||
super(rid, remoteAddr, localAddr);
|
||||
this.#rid = rid;
|
||||
}
|
||||
|
||||
get rid() {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.TlsConn.rid",
|
||||
new Error().stack,
|
||||
"Use `Deno.TlsConn` instance methods instead.",
|
||||
);
|
||||
return this.#rid;
|
||||
}
|
||||
|
||||
handshake() {
|
||||
return opTlsHandshake(this.rid);
|
||||
return opTlsHandshake(this.#rid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
32
ext/net/lib.deno_net.d.ts
vendored
32
ext/net/lib.deno_net.d.ts
vendored
|
@ -69,7 +69,12 @@ declare namespace Deno {
|
|||
readonly localAddr: Addr;
|
||||
/** The remote address of the connection. */
|
||||
readonly remoteAddr: Addr;
|
||||
/** The resource ID of the connection. */
|
||||
/**
|
||||
* The resource ID of the connection.
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.Conn} instance methods instead.
|
||||
* {@linkcode Deno.Conn.rid} will be removed in Deno 2.0.
|
||||
*/
|
||||
readonly rid: number;
|
||||
/** Shuts down (`shutdown(2)`) the write side of the connection. Most
|
||||
* callers should just use `close()`. */
|
||||
|
@ -103,6 +108,13 @@ declare namespace Deno {
|
|||
* not happened yet. Calling this method is optional; the TLS handshake
|
||||
* will be completed automatically as soon as data is sent or received. */
|
||||
handshake(): Promise<TlsHandshakeInfo>;
|
||||
/**
|
||||
* The resource ID of the connection.
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.TlsConn} instance methods instead.
|
||||
* {@linkcode Deno.TlsConn.rid} will be removed in Deno 2.0.
|
||||
*/
|
||||
readonly rid: number;
|
||||
}
|
||||
|
||||
/** @category Network */
|
||||
|
@ -260,6 +272,13 @@ declare namespace Deno {
|
|||
setNoDelay(noDelay?: boolean): void;
|
||||
/** Enable/disable keep-alive functionality. */
|
||||
setKeepAlive(keepAlive?: boolean): void;
|
||||
/**
|
||||
* The resource ID of the connection.
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.Conn} instance methods instead.
|
||||
* {@linkcode Deno.Conn.rid} will be removed in Deno 2.0.
|
||||
*/
|
||||
readonly rid: number;
|
||||
}
|
||||
|
||||
/** @category Network */
|
||||
|
@ -269,8 +288,15 @@ declare namespace Deno {
|
|||
}
|
||||
|
||||
/** @category Network */
|
||||
// deno-lint-ignore no-empty-interface
|
||||
export interface UnixConn extends Conn {}
|
||||
export interface UnixConn extends Conn {
|
||||
/**
|
||||
* The resource ID of the connection.
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.UnixConn} instance methods instead.
|
||||
* {@linkcode Deno.UnixConn.rid} will be removed in Deno 2.0.
|
||||
*/
|
||||
readonly rid: number;
|
||||
}
|
||||
|
||||
/** Connects to the hostname (default is "127.0.0.1") and port on the named
|
||||
* transport (default is "tcp"), and resolves to the connection (`Conn`).
|
||||
|
|
Loading…
Reference in a new issue