Skip to content

Commit 03c25d7

Browse files
committed
Do not use timers-obj
1 parent bc0b3df commit 03c25d7

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v2.1.1 2018-09-17
4+
5+
* Do not use `timers-obj` as far as pure NodeJS timers have better support for
6+
debugging.
7+
38
## v2.1.0 2018-09-17
49

510
* Close file if its file name is already changed even if there is no new data

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "file-timestamp-stream",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Writing stream with file rotating based on timestamp",
55
"main": "lib/file-timestamp-stream.js",
66
"typings": "lib/file-timestamp-stream.d.ts",
@@ -24,18 +24,17 @@
2424
},
2525
"dependencies": {
2626
"stream.finished": "^1.0.1",
27-
"timers-obj": "^0.2.1",
2827
"tslib": "^1.9.3",
2928
"ultra-strftime": "^1.0.2"
3029
},
3130
"devDependencies": {
3231
"@types/chai": "^4.1.4",
3332
"@types/mocha": "^5.2.5",
34-
"@types/node": "^10.9.4",
33+
"@types/node": "^10.10.0",
3534
"@types/ultra-strftime": "^1.0.0",
3635
"chai": "^4.1.2",
3736
"coveralls": "^3.0.2",
38-
"eslint": "^5.5.0",
37+
"eslint": "^5.6.0",
3938
"eslint-config-standard": "^12.0.0",
4039
"eslint-plugin-import": "^2.14.0",
4140
"eslint-plugin-node": "^7.0.1",

src/file-timestamp-stream.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import fs, { WriteStream } from 'fs'
44
import { Writable, WritableOptions } from 'stream'
5-
import { interval, Interval } from 'timers-obj'
65
import strftime from 'ultra-strftime'
76

87
// tslint:disable-next-line:no-var-requires
@@ -33,8 +32,8 @@ export class FileTimestampStream extends Writable {
3332
private streams: Map<string, WriteStream> = new Map()
3433
private streamCancelFinishers: Map<string, () => void> = new Map()
3534
private streamErrorHandlers: Map<string, (err: Error) => void> = new Map()
36-
private closer?: Interval
37-
private closers: Map<string, Interval> = new Map()
35+
private closer?: NodeJS.Timer
36+
private closers: Map<string, NodeJS.Timer> = new Map()
3837

3938
constructor (options: FileTimestampStreamOptions = {}) {
4039
super(options)
@@ -115,8 +114,8 @@ export class FileTimestampStream extends Writable {
115114
this.streams.clear()
116115
}
117116
if (this.closers.size > 0) {
118-
for (const timer of this.closers.values()) {
119-
timer.remove()
117+
for (const closer of this.closers.values()) {
118+
clearInterval(closer)
120119
}
121120
this.streams.clear()
122121
}
@@ -144,7 +143,7 @@ export class FileTimestampStream extends Writable {
144143

145144
if (newFilename !== currentFilename) {
146145
if (currentFilename && stream && closer) {
147-
closer.remove()
146+
clearInterval(closer)
148147
stream.end()
149148

150149
const streamErrorHandler = this.streamErrorHandlers.get(currentFilename)
@@ -167,19 +166,19 @@ export class FileTimestampStream extends Writable {
167166
newStream.on('error', newStreamErrorHandler)
168167
this.streamErrorHandlers.set(newFilename, newStreamErrorHandler)
169168

170-
const newTimer = interval(FileTimestampStream.CLOSE_UNUSED_FILE_AFTER, () => {
169+
const newCloser = setInterval(() => {
171170
if (newFilename !== this.newFilename()) {
172-
newTimer.remove()
171+
clearInterval(newCloser)
173172
this.closers.delete(newFilename)
174173

175174
newStream.end()
176175
}
177-
})
176+
}, FileTimestampStream.CLOSE_UNUSED_FILE_AFTER)
178177
this.closer = closer
179-
this.closers.set(newFilename, newTimer)
178+
this.closers.set(newFilename, newCloser)
180179

181180
const newStreamCancelFinisher = finished(newStream, () => {
182-
newTimer.remove()
181+
clearInterval(newCloser)
183182
this.closers.delete(newFilename)
184183

185184
// tslint:disable-next-line:strict-type-predicates

0 commit comments

Comments
 (0)