11cb0ef41Sopenharmony_ciconst Minipass = require('minipass') 21cb0ef41Sopenharmony_ciconst _flush = Symbol('_flush') 31cb0ef41Sopenharmony_ciconst _flushed = Symbol('_flushed') 41cb0ef41Sopenharmony_ciconst _flushing = Symbol('_flushing') 51cb0ef41Sopenharmony_ciclass Flush extends Minipass { 61cb0ef41Sopenharmony_ci constructor (opt = {}) { 71cb0ef41Sopenharmony_ci if (typeof opt === 'function') 81cb0ef41Sopenharmony_ci opt = { flush: opt } 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci super(opt) 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci // or extend this class and provide a 'flush' method in your subclass 131cb0ef41Sopenharmony_ci if (typeof opt.flush !== 'function' && typeof this.flush !== 'function') 141cb0ef41Sopenharmony_ci throw new TypeError('must provide flush function in options') 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci this[_flush] = opt.flush || this.flush 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci emit (ev, ...data) { 201cb0ef41Sopenharmony_ci if ((ev !== 'end' && ev !== 'finish') || this[_flushed]) 211cb0ef41Sopenharmony_ci return super.emit(ev, ...data) 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci if (this[_flushing]) 241cb0ef41Sopenharmony_ci return 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci this[_flushing] = true 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci const afterFlush = er => { 291cb0ef41Sopenharmony_ci this[_flushed] = true 301cb0ef41Sopenharmony_ci er ? super.emit('error', er) : super.emit('end') 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci const ret = this[_flush](afterFlush) 341cb0ef41Sopenharmony_ci if (ret && ret.then) 351cb0ef41Sopenharmony_ci ret.then(() => afterFlush(), er => afterFlush(er)) 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_cimodule.exports = Flush 40