如何将 Highland 的 wrapCallback 与 n-arity 函数一起使用?

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

我想使用具有以下结构的方法(来自 jsonist): jsonist.get(uri, options, callback)

需要

urioptions(传递某个 header 的选项)

但是我不确定 Highland 的 wrapCallback 是否可以处理这里的两个选项(减去回调)

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

这样记录的是流,而不是数据

有更好的方法吗?

您可以指定参数 inside wrapCallback:

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

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

或者如果回调有 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 })