question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NodeJs - Pause/Resume stream request

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

7reactions
dhensbycommented, May 8, 2019

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) 🎉

3reactions
hosseinGanjyarcommented, May 10, 2019

OH MY GOD…After about 2 years solved this issue.

Tha’s one small step for a man, one giant leap for mankind https://www.linkedin.com/feed/update/urn:li:activity:6531761519288418304/

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found