net-promise
Simple net.Socket promise wrapper.
Installation
npm install --save net-promise
Usage
Basic Usage
The default message handler processes string messages and waits for a message ending with the character \n
to fulfil the promise.
const Socket SocketError SocketErrorType = ; const ping = async let socket; try socket = await ; await socket; const message = await socket; console; //pong catch e if e instanceof SocketError /* CONNECTION_REFUSED TRANSMISSION_ERROR CONNECTION_CLOSED TIMEOUT */ console finally if socket socket;
Idle Timeout
const Socket SocketError SocketErrorType = ; const ping = async let socket; try socket = await ; await socket; catch e if e instanceof SocketError console // TIMEOUT finally if socket socket;
Custom Message Handler
const Socket SocketError SocketErrorType = ; const ping = async const myOwnMessageHandler = { const messages = ; let count = 0; return { count++; console; messages; if count === 10 ; } } let socket; try socket = await ; const message = await socket; console; catch e if e instanceof SocketError console finally if socket socket;
License
This service is licensed under the MIT License.
All files located in the node_modules and external directories are externally maintained libraries used by this software which have their own licenses; we recommend you read them, as their terms may differ from the terms in the MIT License.