/
index.js
36 lines (28 loc) · 798 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
var through = require('@ljharb/through');
var nextTick = typeof setImmediate === 'undefined'
? process.nextTick
: setImmediate;
var callBind = require('call-bind');
/** @type {import('.')} */
module.exports = function resumer(write, end) {
var tr = through(write, end);
tr.pause();
var resume = callBind.apply(tr.resume);
var pause = callBind.apply(tr.pause);
var paused = false;
tr.pause = function () {
paused = true;
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/57164
return pause(this, arguments);
};
tr.resume = function () {
paused = false;
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/57164
return resume(this, arguments);
};
nextTick(function () {
if (!paused) { tr.resume(); }
});
return tr;
};