Files
memecoin-botV2/.pnpm-store/v10/files/1d/8dde5d00be17c355564fbf3cc0e59b244495f82796b35e587f097ab7b4e6da454bfedb36f8524c9222732f7209d3cc425107e3da10a84af3ca99d8b8a8c9b0

69 lines
1.4 KiB
Plaintext

'use strict'
const { EventEmitter } = require('events')
const { parentPort } = require('worker_threads')
function createDestination (mode) {
const destination = new EventEmitter()
destination.writableEnded = false
destination.writableNeedDrain = false
destination.write = function () {
if (mode === 'drain') {
destination.writableNeedDrain = true
setTimeout(() => {
destination.writableNeedDrain = false
parentPort.postMessage({
code: 'EVENT',
name: 'destination-drain'
})
destination.emit('drain')
}, 50)
}
return true
}
destination.end = function () {
destination.writableEnded = true
destination.emit('close')
}
if (mode === 'flush') {
destination.flush = function (cb) {
setTimeout(() => {
parentPort.postMessage({
code: 'EVENT',
name: 'destination-flushed'
})
cb()
}, 50)
}
}
if (mode === 'flush-sync') {
destination.flushSync = function () {
parentPort.postMessage({
code: 'EVENT',
name: 'destination-flush-sync'
})
}
}
if (mode === 'exit-on-flush') {
destination.flush = function (_cb) {
setTimeout(() => {
process.exit(0)
}, 20)
}
}
return destination
}
async function run (opts) {
return createDestination(opts.mode)
}
module.exports = run