-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pEvent does not reliably return when used on same key twice #27
Comments
You need to attach the event listener before the event is emitted. If the const emitter = createSomeEmitter();
emitter.emit('foo');
// Will never be resolved
await pEvent(emitter, 'foo'); const emitter = createSomeEmitter();
// Will be resolved
await pEvent(emitter, 'foo');
emitter.emit('foo'); |
watch = new EventEmitter();
process.setTimeout(() => watch.emit('change'), 0);
return watch; So I have time to add a listener before the event is emitted. |
Oh... I wonder if the library I'm using to talk to etcd is being overly clever, and emitting a |
Yeah, probably. I just tried this and it passed: const createEmitter = () => {
const e = new EventEmitter();
setTimeout(() => e.emit('foo', 'bar'), 0);
return e;
};
const emitter = createEmitter();
const result = await pEvent(emitter, 'foo');
t.is(result, 'bar'); |
Yeah, I tried something similar and it passed for me too. Sorry to waste
your time. :P Thanks for the awesome library, though!
…On Fri, Sep 27, 2019, 15:44 Kevin Mårtensson ***@***.***> wrote:
Yeah, probably. I just tried this and it passed:
const createEmitter = () => {
const e = new EventEmitter();
setTimeout(() => e.emit('foo', 'bar'));
return e;
};
const emitter = createEmitter();const result = await pEvent(emitter, 'foo');
t.is(result, 'bar');
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27?email_source=notifications&email_token=AANQL63ZCVM55SGKLCS2RYDQLZPBLA5CNFSM4I25I7T2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7Z5E5Y#issuecomment-536072823>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANQL6YLFPW6ASBIUSR3WVDQLZPBLANCNFSM4I25I7TQ>
.
|
I'm trying to use p-event in a test case. I have a key-value implementation which is watching a key. There should be a 'change' event fired when I create the watch, and then a second event fired if the key changes:
These two test cases ought to be equivalent, but the first one passes reliably, and the second one prints "here" and then times out waiting for the second
await
(but passes rarely). Am I missing something here?The text was updated successfully, but these errors were encountered: