fromSocket<T extends Socket> 静态方法

ConnectionTask<T> fromSocket<T extends Socket>(
  1. Future<T> socket,
  2. void onCancel()
)

从现有的 Future 创建一个 ConnectionTask

您可以使用此方法在 HttpClient.connectionFactory 中返回现有的套接字连接。

例如

final clientSocketFuture = Socket.connect(
    serverUri.host, serverUri.port);
final client = HttpClient()
 ..connectionFactory = (uri, proxyHost, proxyPort) {
   return Future.value(
       ConnectionTask.fromSocket(clientSocketFuture, () {}));
final response = await client.getUrl(serverUri);

实现

static ConnectionTask<T> fromSocket<T extends Socket>(
        Future<T> socket, void Function() onCancel) =>
    ConnectionTask<T>._(socket, onCancel);