NodeJs - Pause/Resume stream request
See original GitHub issueI fetch n millions records from SqlServer (streaming) and process over every record. I want to call nested functions into request.on(‘row’, row => { }) and pause streaming until end of latest nested functions.
#NodeJs #SqlServer
I want this:
const sql = require('mssql')
sql.connect(config, err => {
// ... error checks
const request = new sql.Request()
request.stream = true // You can set streaming differently for each request
request.query('select * from verylargetable') // or request.execute(procedure)
request.on('recordset', columns => {
// Emitted once for each recordset in a query
})
request.on('row', row => {
// Emitted for each row in a recordset
//call process_1(row)
})
request.on('error', err => {
// May be emitted multiple times
})
request.on('done', result => {
// Always emitted as the last one
})
})
sql.on('error', err => {
// ... error handler
})
function process_1(data){
//process done after n minutes
//if end process, then call process_2(newData)
}
function process_2(newData){
//process done after n minutes
//if end process, then resume streaming request
}
Notice: I road https://github.com/tediousjs/tedious/issues/181 and other issue about pause/pesume stream request but I didn’t get any idea! thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
Node.js Stream readable.pause() Method - GeeksforGeeks
The readable.pause() method is an inbuilt application programming interface of Stream module which is used to stop the flowing mode from ...
Read more >Pausing a readable stream in Node.js - Stack Overflow
The stream is in paused mode when you did rs.pause(). Infact even if you don't do it the ... The stream goes into...
Read more >What is Stream Module pause() in Node.js? - Educative.io
Calling this method halts the reading of data unless readable.resume() is called to resume the process. Nothing is explicitly returned. A user can...
Read more >Stream | Node.js v19.3.0 Documentation
Calling the stream.resume() method. Calling the stream.pipe() method to send the data to a Writable . The Readable can switch back to paused...
Read more >Pause a stream's data events - GitHub
Resume the stream by re-emitting all the data events in the same order, followed by an end event, if that was emitting during...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yep - This was added in #775 and released in v5.0.0 - however, due to a bug in the tedious driver, it didn’t actually work properly and is now in v6.0.0 without any bugs (see #838 and #832) 🎉
OH MY GOD…After about 2 years solved this issue.