mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 14:01:35 +00:00
feat: promisify all api methods that accept callbacks (#381)
* feat: promisify all api methods that accept callbacks This is a stop-gap until the full async/await migration can be completed. It means we can refactor tests of other modules that depend on this module without having to mix async flow control strategies. N.b. some methods that were previously callable without callbacks (e.g. `node.start()`, `node.stop()`, etc) now require callbacks otherwise a promise is returned which, if rejected, can cause `unhandledPromiseRejection` events and lead to memory leaks. * docs: add a global note to the api about promisify * fix: update the logic for unsubscribe * test(fix): correct pubsub unsubscribe usage for api change * test(fix): update content routing tests for latest delegate version
This commit is contained in:
committed by
Jacob Heun
parent
b4a70ea476
commit
df6ef45a2d
@ -60,9 +60,9 @@ describe('libp2p state machine (fsm)', () => {
|
||||
node.once('stop', done)
|
||||
|
||||
// stop the stopped node
|
||||
node.stop()
|
||||
node.stop(() => {})
|
||||
})
|
||||
node.start()
|
||||
node.start(() => {})
|
||||
})
|
||||
|
||||
it('should callback with an error when it occurs on stop', (done) => {
|
||||
@ -79,7 +79,7 @@ describe('libp2p state machine (fsm)', () => {
|
||||
expect(2).checks(done)
|
||||
|
||||
sinon.stub(node._switch, 'stop').callsArgWith(0, error)
|
||||
node.start()
|
||||
node.start(() => {})
|
||||
})
|
||||
|
||||
it('should noop when starting a started node', (done) => {
|
||||
@ -89,13 +89,13 @@ describe('libp2p state machine (fsm)', () => {
|
||||
})
|
||||
node.once('start', () => {
|
||||
node.once('stop', done)
|
||||
node.stop()
|
||||
node.stop(() => {})
|
||||
})
|
||||
|
||||
// start the started node
|
||||
node.start()
|
||||
node.start(() => {})
|
||||
})
|
||||
node.start()
|
||||
node.start(() => {})
|
||||
})
|
||||
|
||||
it('should error on start with no transports', (done) => {
|
||||
@ -115,7 +115,7 @@ describe('libp2p state machine (fsm)', () => {
|
||||
|
||||
expect(2).checks(done)
|
||||
|
||||
node.start()
|
||||
node.start(() => {})
|
||||
})
|
||||
|
||||
it('should not start if the switch fails to start', (done) => {
|
||||
@ -150,7 +150,7 @@ describe('libp2p state machine (fsm)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
node.stop()
|
||||
node.stop(() => {})
|
||||
})
|
||||
|
||||
it('should not dial (fsm) when the node is stopped', (done) => {
|
||||
@ -162,7 +162,7 @@ describe('libp2p state machine (fsm)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
node.stop()
|
||||
node.stop(() => {})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user