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

Commit

Permalink
promise when there's no argument
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobg committed Aug 18, 2020
1 parent a3551d1 commit d6133fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ This script parses a couple of flags from `argv`:
### Update (promise version)
If you are using promises there's now a promise version.
If you are using promises there's now a promise version, if you don't pass a function as second argument:
``` js
const downloader = require('youtube-dl/lib/downloaderPromise')
const downloader = require('youtube-dl/lib/downloader')

downloader('path/to-binary')
.then((message) => {
Expand Down
4 changes: 4 additions & 0 deletions lib/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const request = require('request')
const mkdirp = require('mkdirp')
const path = require('path')
const fs = require('fs')
const util = require('util')

const [, , ...flags] = process.argv

Expand Down Expand Up @@ -77,6 +78,9 @@ function downloader (binDir, callback) {
callback = binDir
binDir = null
}
else if (!callback) {
return util.promisify(downloader)(binDir)
}

createBase(binDir)

Expand Down
8 changes: 0 additions & 8 deletions lib/downloaderPromise.js

This file was deleted.

9 changes: 5 additions & 4 deletions scripts/download.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var downloader = require('../lib/downloader')

downloader(function error (err, done) {
if (err) return console.log(err.stack)
console.log(done)
})
downloader().then((message) => {
console.log(message);
}).catch((err) => {
console.error(err)
});

0 comments on commit d6133fc

Please sign in to comment.