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

Commit e6ded63

Browse files
committed
Rename pub/sub to publish/subscribe
1 parent 4eb223e commit e6ded63

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/api/pubsub.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const parseMessage = (message) => {
3131

3232
module.exports = (send, config) => {
3333
return {
34-
sub: promisify((topic, options, callback) => {
34+
subscribe: promisify((topic, options, callback) => {
3535
if (typeof options === 'function') {
3636
callback = options
3737
options = {}
@@ -79,7 +79,7 @@ module.exports = (send, config) => {
7979
}
8080
callback(null, rs)
8181
}),
82-
pub: promisify((topic, data, options, callback) => {
82+
publish: promisify((topic, data, options, callback) => {
8383
if (typeof options === 'function') {
8484
callback = options
8585
options = {}

test/ipfs-api/pubsub.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const FactoryClient = require('../factory/factory-client')
1010
const topicName = 'js-ipfs-api-tests'
1111

1212
const publish = (ipfs, data, callback) => {
13-
ipfs.pubsub.pub(topicName, data, (err, result) => {
13+
ipfs.pubsub.publish(topicName, data, (err, successful) => {
1414
expect(err).to.not.exist
15-
expect(result).to.equal(true)
15+
expect(successful).to.equal(true)
1616
callback()
1717
})
1818
}
@@ -50,7 +50,7 @@ describe('.pubsub', () => {
5050

5151
describe('.subscribe', () => {
5252
it('one topic', (done) => {
53-
ipfs.pubsub.sub(topicName, (err, subscription) => {
53+
ipfs.pubsub.subscribe(topicName, (err, subscription) => {
5454
expect(err).to.not.exist
5555
subscription.on('data', (d) => {
5656
expect(d.data).to.equal('hi')
@@ -63,9 +63,9 @@ describe('.pubsub', () => {
6363
setTimeout(publish.bind(null, ipfs, 'hi', () => {}), 0)
6464
})
6565
it('fails when already subscribed', (done) => {
66-
ipfs.pubsub.sub(topicName, (firstErr, firstSub) => {
66+
ipfs.pubsub.subscribe(topicName, (firstErr, firstSub) => {
6767
expect(firstErr).to.not.exist
68-
ipfs.pubsub.sub(topicName, (secondErr, secondSub) => {
68+
ipfs.pubsub.subscribe(topicName, (secondErr, secondSub) => {
6969
expect(secondErr).to.be.an('error')
7070
expect(secondErr.toString()).to.equal('Error: Already subscribed to ' + topicName)
7171
firstSub.cancel()
@@ -77,7 +77,7 @@ describe('.pubsub', () => {
7777
let receivedMessages = []
7878
let interval = null
7979
const expectedMessages = 2
80-
ipfs.pubsub.sub(topicName, (err, subscription) => {
80+
ipfs.pubsub.subscribe(topicName, (err, subscription) => {
8181
expect(err).to.not.exists
8282
subscription.on('data', (d) => {
8383
receivedMessages.push(d.data)
@@ -100,7 +100,7 @@ describe('.pubsub', () => {
100100
describe('multiple nodes pub/sub', () => {
101101
it('receive messages from different node', (done) => {
102102
const expectedString = 'hello from the other side'
103-
apiClients.a.pubsub.sub(topicName, (err, subscription) => {
103+
apiClients.a.pubsub.subscribe(topicName, (err, subscription) => {
104104
expect(err).to.not.exists
105105
subscription.on('data', (d) => {
106106
expect(d.data).to.be.equal(expectedString)
@@ -109,7 +109,7 @@ describe('.pubsub', () => {
109109
})
110110
})
111111
setTimeout(() => {
112-
apiClients.b.pubsub.pub(topicName, expectedString, (err, result) => {
112+
apiClients.b.pubsub.publish(topicName, expectedString, (err, result) => {
113113
expect(err).to.not.exist
114114
expect(result).to.equal(true)
115115
})

0 commit comments

Comments
 (0)