Skip to content

Commit 4e5fd14

Browse files
committed
Minor fixes / tweaks
- Unconditionally switch to a local Promise implementation
1 parent e31f45d commit 4e5fd14

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

PromiseStream.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22

3+
var Bluebird = require('bluebird');
4+
35
function PromiseStream (fn, args, size, maxConcurrency) {
46
this._buf = [];
57
this._fn = fn;
@@ -50,9 +52,9 @@ PromiseStream.prototype.next = function () {
5052
}
5153

5254
if (this._buf.length) {
53-
return Promise.resolve(this._buf.shift());
55+
return Bluebird.resolve(this._buf.shift());
5456
} else {
55-
return new Promise(function(resolve, reject) {
57+
return new Bluebird(function(resolve, reject) {
5658
self._waiters.push({
5759
resolve: resolve,
5860
reject: reject

htmldumper.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use strict";
22

3-
if (!global.Promise || !global.promise.promisify) {
4-
global.Promise = require('bluebird');
5-
}
3+
var Bluebird = require('bluebird');
64

75
// Enable heap dumps in /tmp on kill -USR2.
86
// See https://github.com/bnoordhuis/node-heapdump/
@@ -16,7 +14,7 @@ process.on('SIGUSR2', function() {
1614
});
1715

1816
var preq = require('preq');
19-
var fs = Promise.promisifyAll(require('fs'));
17+
var fs = Bluebird.promisifyAll(require('fs'));
2018
var PromiseStream = require('./PromiseStream');
2119

2220
// Article dump parallelism
@@ -26,7 +24,7 @@ function getArticles (options, res) {
2624
var next = res.next || '';
2725
if (next === 'finished') {
2826
// nothing more to do.
29-
return Promise.reject('Articles done');
27+
return Bluebird.reject('Articles done');
3028
}
3129

3230
var url = options.apiURL + '?action=query&generator=allpages&gapfilterredir=nonredirects'
@@ -116,14 +114,14 @@ function dumpArticle (options, title, oldid) {
116114
if (options.saveDir) {
117115
checkRevision = checkArticle(options, title, oldid);
118116
} else {
119-
checkRevision = Promise.resolve(false);
117+
checkRevision = Bluebird.resolve(false);
120118
}
121119

122120
return checkRevision
123121
.then(function(checkResult) {
124122
if (!checkResult) {
125123
console.log('Dumping', title, oldid);
126-
var url = 'http://' + options.host + '/' + options.prefix
124+
var url = options.host + '/' + options.prefix
127125
+ '/v1/page/html/' + encodeURIComponent(title) + '/' + oldid;
128126
return preq.get({
129127
uri: url,
@@ -169,12 +167,12 @@ Dumper.prototype.processArticles = function (newArticles) {
169167
Dumper.prototype.getArticle = function () {
170168
var self = this;
171169
if (this.articles.length) {
172-
return Promise.resolve(this.articles.shift());
170+
return Bluebird.resolve(this.articles.shift());
173171
} else {
174172
if (!this.waiters.length) {
175173
this.articleChunkStream.next().then(this.processArticles.bind(this));
176174
}
177-
return new Promise(function(resolve, reject) {
175+
return new Bluebird(function(resolve, reject) {
178176
self.waiters.push({resolve: resolve, reject: reject});
179177
});
180178
}
@@ -222,19 +220,27 @@ function makeDump (options) {
222220
}
223221

224222
if (module.parent === null) {
225-
var argv = require('yargs')
223+
var argParser = require('yargs')
226224
.usage('Create a HTML dump in a subdir\nUsage: $0'
227-
+ '\nExample: node htmldumper.js --prefix en.wikipedia.org --ns 0 --apiURL http://en.wikipedia.org/w/api.php')
225+
+ '\nExample:\nnode htmldumper.js --prefix en.wikipedia.org --ns 0 --apiURL http://en.wikipedia.org/w/api.php --host http://rest.wikimedia.org')
228226
.demand(['apiURL', 'prefix', 'ns', 'host'])
227+
.options('h', {
228+
alias: 'help'
229+
})
229230
.options('d', {
230231
alias : 'saveDir',
231232
default : ''
232-
})
233+
});
233234
//.default('apiURL', 'http://en.wikipedia.org/w/api.php')
234235
//.default('prefix', 'en.wikipedia.org')
235236
//.default('ns', '0')
236-
//.default('host', 'https://rest.wikimedia.org')
237-
.argv;
237+
//.default('host', 'http://rest.wikimedia.org');
238+
239+
var argv = argParser.argv;
240+
if (argv.h) {
241+
argParser.showHelp();
242+
process.exit(1);
243+
}
238244

239245
argv.ns = Number(argv.ns);
240246
return makeDump(argv)

0 commit comments

Comments
 (0)