Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: promisify node.stop (#1082)
Browse files Browse the repository at this point in the history
* fix: stop() returns a Promise

* chore: Make linter happy
  • Loading branch information
haadcode authored and daviddias committed Nov 17, 2017
1 parent 35687cb commit 9b385ae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/cli/commands/ls.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const utils = require('../utils')
const Unixfs = require('ipfs-unixfs')
const pull = require('pull-stream')

module.exports = {
command: 'ls <key>',
Expand Down
5 changes: 3 additions & 2 deletions src/core/components/stop.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

const series = require('async/series')
const promisify = require('promisify-es6')

module.exports = (self) => {
return (callback) => {
return promisify((callback) => {
callback = callback || function noop () {}
self.log('stop')

Expand Down Expand Up @@ -40,5 +41,5 @@ module.exports = (self) => {
(cb) => self.libp2p.stop(cb),
(cb) => self._repo.close(cb)
], done)
}
})
}
1 change: 0 additions & 1 deletion src/http/api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,3 @@ function toTypeCode (type) {
return 0
}
}

18 changes: 18 additions & 0 deletions test/core/create-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,24 @@ describe('create node', function () {
], done)
})

it('stop as promised', function (done) {
const node = new IPFS({
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
},
Bootstrap: []
}
})

node.once('ready', () => {
node.stop()
.then(done)
.catch(done)
})
})

it('can start node twice without crash', function (done) {
const options = {
repo: createTempRepo(),
Expand Down

0 comments on commit 9b385ae

Please sign in to comment.