@tootallnate/once

WebJar for @tootallnate/once

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

tootallnate__once
Последняя версия

Последняя версия

1.1.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

@tootallnate/once
WebJar for @tootallnate/once
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/TooTallNate/once

Скачать tootallnate__once

Как подключить последнюю версию

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

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

@tootallnate/once

Creates a Promise that waits for a single event

Installation

Install with npm:

$ npm install @tootallnate/once

API

once<T>(emitter: EventEmitter, name: string): CancelablePromise<T>

Creates a promise that waits for event name name to occur and resolves the promise with the value of the first argument of the event handler function. If an error event occurs before the event specified by name, then the promise is rejected with the error argument.

The promise is cancelable, meaning that you may invoke promise.cancel() to remove the event handlers. The promise will never resolve in this case.

import once from '@tootallnate/once';
import { EventEmitter } from 'events';

const emitter = new EventEmitter();
const result = await once<string>(emitter, 'foo');
console.log(`got ${result}`);

// ... elsewhere ...
emitter.emit('foo', 'bar');
// "got bar"

once.spread<T>(emitter: EventEmitter, name: string): CancelablePromise<T>

Similar to the main once() function, except this version is for the less common scenario of there being more than one parameter provided to the event handler (for example, a ChildProcess "exit" event is provided with two arguments: code and signal).

When using TypeScript, the T generic type must extend Array.

import once from '@tootallnate/once';
import { spawn } from 'child_process';

const child = spawn('ls', [], { stdio: 'inherit' });

// If the process exited, `code` is the final exit code of the process, otherwise `null`.
// If the process terminated due to receipt of a signal, `signal` is the string name of the signal, otherwise `null`.
// One of the two will always be non-`null`.
const [ code, signal ] = await once.spread<[number | null, string | null]>(child, 'exit');

console.log(`child process exited with code=${code}, signal=${signal}`);

Версии библиотеки

Версия
1.1.2