Socket
Socket
Sign inDemoInstall

promise-cs

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    promise-cs

Promise manageable from outer scope, similar to C#'s TaskCompletionSource


Version published
Weekly downloads
3
Maintainers
1
Install size
8.29 kB
Created
Weekly downloads
 

Readme

Source

Promise Completion Source

Promise manageable from outer scope, similar to C#'s TaskCompletionSource

Synopsis

class PromiseSource<TResult> {
    get promise(): Promise<TResult>;
    get resolved(): boolean;
    get rejected(): boolean;
    get completed(): boolean;
    constructor(timeout?: number);
    reject(reason?: any): void;
    resolve(value?: TResult): void;
}

Example

import PromiseSource from "promise-cs";

function doSomething(): Promise<number>
{
	let ps = new PromiseSource<number>(/* optional timeout in millisecond */);

	// Some async action, event or something
	someAsyncAction((err, result) => {
		if (err) {
			ps.reject(err);
			return;
		}
		
		ps.resolve(result);
	});

	return ps.promise;
}

doSomething()
	.then(num => console.log(num))
	.catch(reason => console.error(reason))
;

Keywords

FAQs

Last updated on 11 Jun 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc