Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Add shouldSendCallback, set*Callback methods #220

Merged
merged 3 commits into from
Oct 26, 2016
Merged

Conversation

LewisJEllis
Copy link
Contributor

No description provided.


// neither of these should fire, so report err to done if they do
client.on('logged', done);
client.on('error', done);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this just end the test if they are invoked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done takes an err argument so if anything is passed to it the test fails; lets you easily say "as long as this callback isn't passed an error, we're good".

var original = this[propertyName];
if (typeof callback === 'function') {
this[propertyName] = function (data) {
return callback(data, original);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that verifies that original is passed if there is a pre-existing callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

this.send(kwargs, cb);
} else {
setImmediate(function () {
// wish there was a good way to communicate to cb why we didn't send; worth considering cb api change?
// avoiding setImmediate here because node 0.8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Any thoughts on what this might look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just make the eventId param be something like { eventId: ..., sent: bool, reason: string } but that seems kind of hacky. I think it's probably fine, I can't come up with a compelling reason that isn't satisfied by some extra checks/logic in the shouldSendCallback.

@LewisJEllis LewisJEllis changed the base branch from timing-etc to master October 25, 2016 21:58
zlib.inflate(new Buffer(body, 'base64'), function (err, dec) {
if (err) return done(err);
var msg = JSON.parse(dec.toString());
msg.extra.foo.should.equal('bar');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this assertion / zlib.inflate run before done is called on L473?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught me slippin again. I'm actually not sure, could go either way depending on implementation details. Switched to inflateSync to be more obviously sequenced.

@benvinegar
Copy link
Contributor

wfm (although tests are failing)

@LewisJEllis LewisJEllis merged commit c3fffb3 into master Oct 26, 2016
@LewisJEllis LewisJEllis deleted the should-send-data branch October 26, 2016 01:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants