Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

fix: make pubsub.unsubscribe async and alter pubsub.subscribe signature #260

Merged
merged 8 commits into from
May 11, 2018

Conversation

daviddias
Copy link
Contributor

Fix the flaky tests and API.

@ghost ghost assigned daviddias Apr 30, 2018
@ghost ghost added the in progress label Apr 30, 2018
@daviddias
Copy link
Contributor Author

daviddias commented May 1, 2018

Missing:

  • Update tests
  • Update js-ipfs-api
  • Update js-ipfs

I want to land this before the next release of js-ipfs

@alanshaw
Copy link
Contributor

alanshaw commented May 1, 2018

Ha, nice. I had to make unsubscribe async in ipfs-postmsg-proxy https://github.com/tableflip/ipfs-postmsg-proxy#pubsub-unsubscribe as there's no way to sync over postMessage so the spec is now in line with my implementation :D

SPEC/PUBSUB.md Outdated
- `options: Object`: Object containing the following properties:
- `topic: string`
- `discover: Boolean` - Will use the DHT to find other peers.
- `handler: (msg) => ()` - Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: string, seqno: Buffer, data: Buffer, topicIDs: Array<string>}`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The handler moves into the options object? That's a bit of a weird pattern, much nicer when it was separated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm torn here. The thing is that promisify'ing things forces a weird arg check case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @victorbjelkholm on this one, I'd prefer that the implementation choices in js-ipfs didn't affect the public API.

i.e. I don't think promisify should dictate what our public API looks like even if it means handling some difficult argument combinations.

IMHO the most intuitive API would be this:

ipfs.pubsub.subscribe(topic, handler, options, callback)
ipfs.pubsub.unsubscribe(topic, handler, callback)

Most important and non-optional arguments first, followed by optional args.

That said, if you just renamed the options arg to something like details then that would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe your proposal of:

ipfs.pubsub.subscribe(topic, handler, options, callback)
ipfs.pubsub.unsubscribe(topic, handler, callback)

Pretty much solves the main issue. I like it!

@daviddias
Copy link
Contributor Author

@alanshaw wanna take this API, spec and tests change from me?

@alanshaw
Copy link
Contributor

alanshaw commented May 8, 2018

Yes

@alanshaw alanshaw assigned alanshaw and unassigned daviddias May 8, 2018
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
@alanshaw alanshaw changed the title wip: Fix pubsub fix: make pubsub.unsubscribe async and alter pubsub.subscribe signature May 9, 2018
@alanshaw
Copy link
Contributor

alanshaw commented May 9, 2018

@diasdavid I think this and ipfs/js-ipfs#1348 and ipfs-inactive/js-ipfs-http-client#760 are good for a review now 🚀

Copy link
Contributor Author

@daviddias daviddias left a comment

Choose a reason for hiding this comment

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

Excellent! 👌🏽

@daviddias
Copy link
Contributor Author

@alanshaw feel empowered to merge and release this one :) (as minor).

@alanshaw
Copy link
Contributor

I am need 1 approving review

@alanshaw alanshaw merged commit f4153be into master May 11, 2018
@alanshaw alanshaw deleted the fix-pubsub branch May 11, 2018 16:13
@ghost ghost removed the in progress label May 11, 2018
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.

3 participants