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

Commit 70f24fe

Browse files
authored
Merge pull request #294 from Dahaden/dhaden/#287-flush-promise
#287 Flush now returns promises correctly
2 parents a7fa1c8 + 2c42aa3 commit 70f24fe

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ class Analytics {
238238
callback = callback || noop
239239

240240
if (!this.enable) {
241-
return setImmediate(callback)
241+
setImmediate(callback)
242+
return Promise.resolve()
242243
}
243244

244245
if (this.timer) {
@@ -247,7 +248,8 @@ class Analytics {
247248
}
248249

249250
if (!this.queue.length) {
250-
return setImmediate(callback)
251+
setImmediate(callback)
252+
return Promise.resolve()
251253
}
252254

253255
const items = this.queue.splice(0, this.flushAt)
@@ -286,14 +288,19 @@ class Analytics {
286288
}
287289

288290
return this.axiosInstance.post(`${this.host}${this.path}`, data, req)
289-
.then(() => done())
291+
.then(() => {
292+
done()
293+
return Promise.resolve(data)
294+
})
290295
.catch(err => {
291296
if (err.response) {
292297
const error = new Error(err.response.statusText)
293-
return done(error)
298+
done(error)
299+
throw error
294300
}
295301

296302
done(err)
303+
throw err
297304
})
298305
}
299306

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"husky": "^3.0.4",
5555
"np": "^7.5.0",
5656
"nyc": "^15.1.0",
57-
"pify": "^4.0.1",
5857
"sinon": "^7.3.2",
5958
"snyk": "^1.171.1",
6059
"standard": "^12.0.1"

test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import bodyParser from 'body-parser'
33
import express from 'express'
44
import delay from 'delay'
55
import auth from 'basic-auth'
6-
import pify from 'pify'
76
import test from 'ava'
87
import Analytics from '.'
98
import { version } from './package'
@@ -28,7 +27,6 @@ const createClient = options => {
2827
}, options)
2928

3029
const client = new Analytics('key', options)
31-
client.flush = pify(client.flush.bind(client))
3230
client.flushed = true
3331

3432
return client

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6011,11 +6011,6 @@ pify@^3.0.0:
60116011
resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"
60126012
integrity sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=
60136013

6014-
pify@^4.0.1:
6015-
version "4.0.1"
6016-
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
6017-
integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==
6018-
60196014
pinkie-promise@^1.0.0:
60206015
version "1.0.0"
60216016
resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-1.0.0.tgz#d1da67f5482563bb7cf57f286ae2822ecfbf3670"

0 commit comments

Comments
 (0)