Should I implement 'finally' ? #20

Open
FugueNation opened this Issue Sep 19, 2011 · 3 comments

Projects

None yet

3 participants

@FugueNation

I'm using Seq to handle ordered queries to my DB (using generic-pool), so I need to close the DB's client once I'm done, but if there is an error somewhere along the line it doesn't get closed (well it does if I close in the catch, but then I need to close in both the catch and the final seq command). So I realized that what I needed was a "finally" command.

 connector.acquire( function (err, client) {
     Seq( )
         .seq( function ( ) {
             client.query( 'CREATE DATABASE IF NOT EXISTS ?', options.database, this );
         })
         .seq( function ( ) {
             var query = 'CREATE TABLE IF NOT EXISTS MYTABLE ( ... )';
             client.query( query, this );
         })
...
        .catch( function ( err ) {
            console.log('error', err);
        })
        .finally( function ( ) {
            connector.release(client);
        });

I began implementing it but wasn't sure if there might already be someway to handle this sort of situation.

@FugueNation

submitted a pull request

@yasuoza
yasuoza commented Mar 17, 2012

In this case and maybe a lot of cases, it is useful when error is detected, catch terminates the chain.
How do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment