Permalink
Browse files

Emit both event; Add license

  • Loading branch information...
wdavidw committed Nov 23, 2011
1 parent 7405a4e commit d1fb70b26ceef1eefeb41198e81f81e5a23ffb9f
Showing with 44 additions and 4 deletions.
  1. +6 −1 README.md
  2. +17 −2 lib/hive.coffee
  3. +15 −0 license.md
  4. +6 −1 test/QueryTest.coffee
View
@@ -100,6 +100,11 @@ The following events are emitted:
- `end`
Emitted when there are no more rows to retrieve, not called if there was
an error before.
+- `both`
+ Convenient event combining the `error` and `end` events. Emitted when an
+ error occured or when there are no more rows to retrieve. Return the same
+ arguments than the `error` or `end` event depending on the operation
+ outturn.
The `client.query` functionreturn a Node [Readable Stream][4]. It is possible to
pipe the data into a [Writable Stream][5] but it is your responsibility to emit
@@ -168,7 +173,7 @@ the tests. A database `test_database` will be created if it does not yet exist
and all the tests will run on it.
```bash
- expresso -s test
+ expresso -s
```
[1]: http://hive.apache.org "Apache Hive"
View
@@ -36,7 +36,14 @@ module.exports.createClient = (options = {}) ->
client.execute query, (err) ->
if err
emitter.readable = false
- emitter.emit 'error', err if emitter.listeners('error').length
+ # emit error only if
+ # - there is an error callback
+ # - there is no error callback and no both callback
+ lerror = emitter.listeners('error').length
+ lboth = emitter.listeners('both').length
+ emitError = lerror or (not lerror and not lboth)
+ emitter.emit 'error', err if emitError
+ emitter.emit 'both', err
return
fetch()
exec() if query
@@ -59,7 +66,14 @@ module.exports.createClient = (options = {}) ->
handle = (err, rows) =>
if err
emitter.readable = false
- emitter.emit 'error', err
+ # emit error only if
+ # - there is an error callback
+ # - there is no error callback and no both callback
+ lerror = emitter.listeners('error').length
+ lboth = emitter.listeners('both').length
+ emitError = lerror or (not lerror and not lboth)
+ emitter.emit 'error', err if emitError
+ emitter.emit 'both', err
return
rows = rows.map (row) -> row.split '\t'
for row in rows
@@ -71,6 +85,7 @@ module.exports.createClient = (options = {}) ->
emitter.emit 'row-last', row, count - 1
emitter.readable = false
emitter.emit 'end'
+ emitter.emit 'both'
fetch = ->
return if emitter.paused or not emitter.readable
if size
View
@@ -0,0 +1,15 @@
+Software License Agreement (BSD License)
+========================================
+Copyright (c) 2011, SARL Adaltas.
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+- Neither the name of SARL Adaltas nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the SARL Adaltas.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -62,14 +62,19 @@ module.exports =
assert.eql count, 54
next()
'Query # error': (next) ->
+ error_called = false
client.query("select * from undefined_table", 10)
.on 'row', (row) ->
assert.ok false
.on 'error', (err) ->
assert.ok err instanceof Error
- next()
+ error_called = true
.on 'end', ->
assert.ok false
+ .on 'both', (err) ->
+ assert.ok err instanceof Error
+ assert.ok error_called
+ next()
'Query # pause/resume': (next) ->
count = 0
query = client.query("select * from #{table}", 10)

0 comments on commit d1fb70b

Please sign in to comment.