Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-socket

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-socket

Return promise for socket stream

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4K
increased by5.42%
Maintainers
1
Weekly downloads
 
Created
Source

promise-socket

Build Status Coverage Status npm

This module allows to convert net.Socket stream into its promisified version, which returns Promise object fulfilled when stream's events occurred.

Requirements

This module requires Node >= 4.

Installation

npm install promise-socket

Usage

constructor
const promiseSocket = new PromiseSocket(socket)

PromiseSocket object requires socket object to work. New net.Socket object is created if socket argument is missing.

Example:

const net = require('net')
const { PromiseSocket } = require('promise-socket')

const socket = new net.Socket()

const promiseSocket = new PromiseSocket(socket)

Typescript:

import * as net 'net'
import { PromiseSocket } as 'promise-socket'

const socket = new net.Socket()

const promiseSocket = new PromiseSocket(socket)
stream
const socket = promiseSocket.stream

Original socket object.

Example:

console.log(promiseSocket.stream.localAddress)
setTimeout(ms)

Set the timeout for idle socket and after this timeout the socket will be ended. It means that read or write methods will be also fulfilled.

socket.setTimeout(1000)
await socket.readAll()
stream
const stream = promiseDuplex.stream

Original stream object.

Example:

console.log(promiseDuplex.stream.localAddress)
read
const chunk = await promiseDuplex.read(chunkSize)

Check PromiseReadable.read for details.

readAll
const content = await promiseDuplex.readAll()

Check PromiseReadable.readAll for details.

write
await promiseDuplex.write(chunk)

Check PromiseWritable.write for details.

writeAll
await promiseDuplex.writeAll(content, chunkSize)

Check PromiseWritable.writeAll for details.

end
await promiseDuplex.end()

Check PromiseWritable.once for details.

once
const result = await promiseDuplex.once(event)

Check PromiseReadable.once and PromiseWritable.once for details.

License

Copyright (c) 2017 Piotr Roszatycki piotr.roszatycki@gmail.com

MIT

Keywords

FAQs

Package last updated on 06 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc