fromSocket<T extends Socket> static method
- Future<
T> socket, - void onCancel()
Create a ConnectionTask
from an existing Future<Socket>
.
You can use this method to return existing socket connections in HttpClient.connectionFactory.
For example:
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);
Implementation
static ConnectionTask<T> fromSocket<T extends Socket>(
Future<T> socket,
void Function() onCancel,
) => ConnectionTask<T>._(socket, onCancel);