@@ -92,8 +92,8 @@ class ZooKeeperPromise extends ZooKeeper {
92
92
/**
93
93
* @param path {string}
94
94
* @param watch {boolean}
95
- * @fulfill {Array.<string>>,< stat>}
96
- * @returns {Promise.<Array.<string>>,< stat> }
95
+ * @fulfill {Array} [children, stat] - children: an array of strings, stat: object
96
+ * @returns {Promise.<Array> } [children, stat] - children: an array of strings, stat: object
97
97
*/
98
98
get_children2 ( path , watch ) {
99
99
return this . promisify ( super . a_get_children2 , [ path , watch ] ) ;
@@ -102,8 +102,8 @@ class ZooKeeperPromise extends ZooKeeper {
102
102
/**
103
103
* @param path {string}
104
104
* @param watchCb {function}
105
- * @fulfill {Array.<string>>,< stat>}
106
- * @returns {Promise.<Array.<string>>,< stat> }
105
+ * @fulfill {Array} [children, stat] - children: an array of strings, stat: object
106
+ * @returns {Promise.<Array> } [children, stat] - children: an array of strings, stat: object
107
107
*/
108
108
w_get_children2 ( path , watchCb ) {
109
109
return this . promisify ( super . aw_get_children2 , [ path , watchCb ] ) ;
@@ -166,16 +166,12 @@ class ZooKeeperPromise extends ZooKeeper {
166
166
*/
167
167
promisify ( fn , args ) {
168
168
return new ZkPromise ( ( resolve , reject ) => {
169
- const callback = ( rc , error , result ) => {
170
- if ( rc ) {
171
- reject ( rc ) ;
172
- } else if ( args . length > 3 ) {
173
- // if there are multiple success values, we return an array
174
- Array . prototype . shift . call ( args , 1 ) ;
175
- Array . prototype . shift . call ( args , 1 ) ;
176
- resolve ( args ) ;
169
+ const callback = ( rc , error , ...result ) => {
170
+ if ( rc !== 0 ) {
171
+ reject ( new Error ( `${ rc } ${ error } ` ) ) ;
177
172
} else {
178
- resolve ( result ) ;
173
+ const toReturn = result . length === 1 ? result [ 0 ] : result ;
174
+ resolve ( toReturn ) ;
179
175
}
180
176
} ;
181
177
fn . bind ( this ) ( ...args , callback ) ;
0 commit comments