How to use Highland's wrapCallback with an n-arity function?

129 views Asked by At

I'd like to use a method (from jsonist) with the following structure: jsonist.get(uri, options, callback)

uri and options are needed (options for passing a certain header)

However I'm not certain that Highland's wrapCallback can handle the two options here (minus the callback)

const H = require('highland') const req = H.wrapCallback(jsonist.get) req(uri, options).apply(H.log)

With this the stream is logged, not the data

Is there a better way to do this?

1

There are 1 answers

0
amsross On BEST ANSWER

You can either specify the params inside wrapCallback:

const req = H.wrapCallback((uri, options, cb) => get(uri, options, cb))

req('some.uri', { options })

Or you could use a generator directly if the callback has artiy > 2:

const req = (uri, options) => H(push => {
  get(uri, options, (err, res, body) => {
    push(err, body)
    push(null, h.nil)
  })
})

req('some.uri', { options })