Open maidh91 opened 2 days ago
Pear.Worker.run
pipe.end
pipe.destroy
Parent calls pipe.end()
pipe.end()
end
close
Parent calls pipe.destroy()
pipe.destroy()
Worker calls pipe.end()
Sample Parent code
const pipe = Pear.worker.run('../worker-code') pipe.on('data', (data) => { console.log(data.toString()) }) pipe.on('end', () => { console.log('end') }) pipe.on('close', () => { console.log('close') }) pipe.write('hello') await new Promise((resolve) => setTimeout(resolve, 2000)) // pipe.end() // pipe.destroy() await new Promise((resolve) => setTimeout(resolve, 20000))
Sample Worker code
import fs from 'bare-fs' const pipe = Pear.worker.pipe() pipe.on('data', (data) => { pipe.write('world') fs.writeFileSync('/tmp/test-data', data.toString()) }) pipe.on('end', () => { fs.writeFileSync('/tmp/test-end', 'end') }) pipe.on('close', () => { fs.writeFileSync('/tmp/test-close', 'close') }) await new Promise((resolve) => setTimeout(resolve, 2000)) // pipe.end() // pipe.destroy()
pear.dev run -d parent-code-dir
/tmp/test-data
/tmp/test-end
/tmp/test-close
App Type
Pear.Worker.run
api to start Worker processpipe.end
orpipe.destroy
Scenarios
Parent calls
pipe.end()
end
eventclose
eventend
eventclose
eventParent calls
pipe.destroy()
end
eventclose
eventclose
event only (noend
event)Worker calls
pipe.end()
end
eventclose
eventend
eventclose
eventWorker calls
pipe.end()
close
event only (noend
event)end
eventclose
eventHow to test
Sample Parent code
Sample Worker code
pear.dev run -d parent-code-dir
/tmp/test-data
,/tmp/test-end
,/tmp/test-close
for worker events