2-thenable

WebJar for 2-thenable

License

License

ISC
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

2-thenable
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

2-thenable
WebJar for 2-thenable
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/medikoo/2-thenable

Download 2-thenable

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/2-thenable/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>2-thenable</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/2-thenable/
implementation 'org.webjars.npm:2-thenable:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/2-thenable/
implementation ("org.webjars.npm:2-thenable:1.0.0")
'org.webjars.npm:2-thenable:jar:1.0.0'
<dependency org="org.webjars.npm" name="2-thenable" rev="1.0.0">
  <artifact name="2-thenable" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='2-thenable', version='1.0.0')
)
libraryDependencies += "org.webjars.npm" % "2-thenable" % "1.0.0"
[org.webjars.npm/2-thenable "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : d jar [1,2)
org.webjars.npm : es5-ext jar [0.10.47,0.11)

Project Modules

There are no modules declared in this project.

*nix build status Windows build status Tests coverage Transpilation status npm version

2-thenable

Convert object into a thenable

Useful when we want to imply an asynchronous representation onto some non-promise object.

Having that target object can be combined into promise chains or async/await syntax. One use case would be turning a stream instance so it's also a promise.

Installation

npm install 2-thenable

How it works

Utility takes target and promise arguments. target is object to be extended with then, catch and finally methods. While promise is expected to be a native promise instance that reflects resolution which should be mapped onto target

Usage

Example of converting stream to thenable

const toThenable = require("2-thenable");

// Example of converting a simple utf8 string stream to thenable
toThenable(stream, new Promise((resolve, reject) => {
	let result = '';
	stream.on('error', reject);
	stream.on('data', data => (result += data));
	stream.on('end', () => resolve(result));
});

stream.then(result => {
	console.log("Cumulated string data", result);
});

Tests

npm test

Versions

Version
1.0.0