Skip to content

resolve ​

resolve resuelve un nombre de host o una dirección en direcciones textuales.

La resolución es asíncrona y acepta un timeout opcional en milisegundos. Los fallos de red cumplen la promesa con Err(NetError).

Firmaresolve(host: string, timeoutMs?: u64): Promise<Result<string[], NetError>>
tyrus
import { NetError, resolve } from "tyrus:net";

async function lookup(): Promise<void> {
    const result: Result<string[], NetError> = await resolve("localhost", 1000);
    match (result) {
        Ok(addresses) => { print(addresses.length); } // 1
        Err(error) => { printError(error.code); } // ERR_NET_RESOLVE
    }
}

Manejo de errores ​

error

tyrus
import { NetError, resolve } from "tyrus:net";

async function lookup(): Promise<void> {
    const result: Result<string[], NetError> = await resolve("invalid.invalid", 1000);
    match (result) {
        Ok(_) => {}
        Err(error) => { printError(error.code); } // ERR_NET_RESOLVE
    }
}

Los fallos habituales incluyen ERR_NET_RESOLVE y ERR_NET_TIMEOUT.