зеркало из https://github.com/microsoft/etcd3.git
Address PR comments
This commit is contained in:
Родитель
0c2b57e6e5
Коммит
898cfdf7ed
|
@ -244,7 +244,7 @@ export class Lease extends EventEmitter {
|
|||
// far past the end of our key's TTL, there's no way we're going to be
|
||||
// able to renew it. Fire a "lost".
|
||||
if (Date.now() - this.lastKeepAlive > 2 * 1000 * this.ttl) {
|
||||
this.emit('lost', new GRPCConnectFailedError('We lost connect to etcd and our lease has expired.'));
|
||||
this.emit('lost', new GRPCConnectFailedError('We lost connection to etcd and our lease has expired.'));
|
||||
return this.close();
|
||||
}
|
||||
|
||||
|
|
18
src/util.ts
18
src/util.ts
|
@ -157,13 +157,23 @@ export function forOwn<T>(obj: T, iterator: <K extends keyof T>(value: T[K], key
|
|||
* fire on the emitter.
|
||||
*/
|
||||
export function onceEvent(emitter: EventEmitter, ...events: string[]): Promise<any> {
|
||||
return new Promise(resolve => {
|
||||
const handler = (data: any) => {
|
||||
events.forEach(name => emitter.removeListener(name, handler));
|
||||
return new Promise((resolve, reject) => {
|
||||
const teardown: (() => void)[] = [];
|
||||
|
||||
const handler = (data: any, event: string) => {
|
||||
teardown.forEach(t => t());
|
||||
if (event === 'error') {
|
||||
reject(data);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
};
|
||||
|
||||
events.forEach(event => emitter.once(event, handler));
|
||||
events.forEach(event => {
|
||||
const fn = (data: any) => handler(data, event);
|
||||
teardown.push(() => emitter.removeListener(event, fn));
|
||||
emitter.once(event, fn);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -321,13 +321,7 @@ export class WatchBuilder {
|
|||
this.namespace.applyToRequest(this.request),
|
||||
);
|
||||
|
||||
return onceEvent(watcher, 'connected', 'error').then(res => {
|
||||
if (res instanceof Error) {
|
||||
throw res;
|
||||
}
|
||||
|
||||
return watcher;
|
||||
});
|
||||
return onceEvent(watcher, 'connected').then(() => watcher);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче