Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hookyns/promisesource
Promise manageable from outer scope, similar to C#'s TaskCompletionSource
https://github.com/hookyns/promisesource
completion javascript nodejs promise source taskcompletionsource typescript
Last synced: about 2 months ago
JSON representation
Promise manageable from outer scope, similar to C#'s TaskCompletionSource
- Host: GitHub
- URL: https://github.com/hookyns/promisesource
- Owner: Hookyns
- License: mit
- Created: 2020-06-11T19:07:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-09T13:54:40.000Z (over 4 years ago)
- Last Synced: 2024-04-28T05:29:01.265Z (9 months ago)
- Topics: completion, javascript, nodejs, promise, source, taskcompletionsource, typescript
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Promise Completion Source
Promise manageable from outer scope, similar to C#'s TaskCompletionSource## Synopsis
```typescript
class PromiseSource {
get promise(): Promise;
get resolved(): boolean;
get rejected(): boolean;
get completed(): boolean;
constructor(timeout?: number);
reject(reason?: any): void;
resolve(value?: TResult): void;
}
```## Example
```typescript
import PromiseSource from "promise-cs";function doSomething(): Promise
{
let ps = new PromiseSource(/* 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))
;
```