dengelke / node-zoom2

z39.50 with Node 12+ support
MIT License
13 stars 4 forks source link

Connection.close() is missing #22

Open andrisi opened 2 years ago

andrisi commented 2 years ago

So the node app doesn't exit.

dengelke commented 2 years ago

Connection has a method Connection.destroy() which should provide the required functionality

dengelke commented 2 years ago

Should now be fixed, please use version 0.7.2

dengelke commented 2 years ago

Closing issue for now, please reopen again if not resolved

andrisi commented 2 years ago

It still says "this._conn.destroy is not a function" when calling a connection's destroy method, because it's called "destory" in the _conn object. Actually something else is broken too, as the Record's _record is null to after getting it from the Resultset. Version 0.6.2 works ok.

dengelke commented 2 years ago

@andrisi I've published 0.7.3 which fixes the typo in connection - do you have a code example for the Record's _record is null to after getting it from the Resultset?

andrisi commented 2 years ago

Connectiondestroy() works ok now.

The problem with destroying recordsets is that because resultset.getRecords() uses a callback and it does not support async functions, it's sort of hard to find the moment where you'd call resultset.destroy(). I need to emit an event and pass the record to the outside to be able to use database calls for example. Could you support async event handlers for getRecords - that is waiting for completition if the result of the function is a promise? Or suggest another way?

andrisi commented 2 years ago

Sorry, I actually could find a place to close the resultset - with an example where I do not need to use db operations, see:

    this.z.query('prefix', query).search((err, resultset) => {

        if(err)
        {
            console.log(err)
            return
        }

        hits = resultset.size

        if(hits > 0 && hits < 10000)
        {               
            resultset.getRecords(0, hits, (err, records) => {

                while (records && records.hasNext()) 
                {
                    let record = records.next()
                    let marc = new Record(record.json)
                    marc.dumpMain()
                }   

                event.emit('done', resultset)
            })   

        }
        else
        {
            event.emit('done')
        }

    })

    let recordsetToClose = await pEvent(event, 'done')

    recordsetToClose.destroy()
andrisi commented 2 years ago

The one that uses async db functions does a event.emit('record', record) for each record and then a listener does the save op asyncronously. This might make some queues big, but that's not so important with small recordsets.