From 07c7f198dbfa75dffbf45f91eab6fb535056af94 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Thu, 4 May 2017 15:33:14 +0200 Subject: stream: add final method Adds the ability to for write streams to have an _final method which acts similarly to the _flush method that transform streams have but is called before the finish event is emitted and if asynchronous delays the stream from finishing. The `final` option may also be passed in order to set it. PR-URL: https://github.com/nodejs/node/pull/12828 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Refael Ackermann --- ...est-stream-transform-constructor-set-methods.js | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/parallel/test-stream-transform-constructor-set-methods.js') diff --git a/test/parallel/test-stream-transform-constructor-set-methods.js b/test/parallel/test-stream-transform-constructor-set-methods.js index 1423f4de10..3e1325c0fd 100644 --- a/test/parallel/test-stream-transform-constructor-set-methods.js +++ b/test/parallel/test-stream-transform-constructor-set-methods.js @@ -1,24 +1,25 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const Transform = require('stream').Transform; -let _transformCalled = false; -function _transform(d, e, n) { - _transformCalled = true; +const _transform = common.mustCall(function _transform(d, e, n) { n(); -} +}); -let _flushCalled = false; -function _flush(n) { - _flushCalled = true; +const _final = common.mustCall(function _final(n) { n(); -} +}); + +const _flush = common.mustCall(function _flush(n) { + n(); +}); const t = new Transform({ transform: _transform, - flush: _flush + flush: _flush, + final: _final }); const t2 = new Transform({}); @@ -34,6 +35,5 @@ assert.throws(() => { process.on('exit', () => { assert.strictEqual(t._transform, _transform); assert.strictEqual(t._flush, _flush); - assert.strictEqual(_transformCalled, true); - assert.strictEqual(_flushCalled, true); + assert.strictEqual(t._final, _final); }); -- cgit v1.2.1