dgram-as-promised
This module provides promisified version of standard
dgram class. The API is
the same as for standard dgram
, except bind
, close
and send
methods
which return
Promise
object.
Requirements
This module requires ES6 with Node >= 10.
Installation
npm install dgram-as-promised
Additionally for Typescript:
npm install -D @types/node
Usage
dgram-as-promised
can be used similar to standard dgram
module.
Example:
const DgramAsPromised = const socket = DgramAsPromised const MEMBERSHIP = "224.0.0.1"const PORT = 41234 const message = Buffer
Typescript:
// or
bind
Method bind
returns Promise
object which resolves to address info when
listening
event is emitted.
const address = await socketconsole socketsocket socketconsole
send
Method send
returns Promise
object which is fulfilled when message has been
sent.
const bytes = await socketconsole
recv
Method recv
returns Promise
object which resolves to the object with msg
and rinfo
properties as from message
event or resolves to undefined
when
socket is already closed.
const packet = await socketif packet console console
close
Method close
returns Promise
object which resolves when close
event is
emitted.
await socketconsole
iterate
Method iterate
and the socket object return asynchronous iterator which will
call recv
method until socket is closed.
for { console // Close socket if Ctrl-D is in the message if packetmsg !== -1 await socket }
destroy
Method destroy
cleans internal listeners.
socket
License
Copyright (c) 2016-2020 Piotr Roszatycki mailto:piotr.roszatycki@gmail.com