How to use the wrapCallback function from highland

Find comprehensive JavaScript highland.wrapCallback code examples handpicked from public code repositorys.

highland.wrapCallback is a higher-order function that takes a callback-based function and returns a new function that works with Highland streams.

16
17
18
19
20
21
22
23
24

var H = require('highland');
var fs = require('fs');
var mac = require('../index.js');

var readdir = H.wrapCallback(fs.readdir);
var readFile = H.wrapCallback(fs.readFile);

var playback = new mac.Playback(0, mac.bmdModeHD1080i50, mac.bmdFormat10BitYUV);
fork icon19
star icon93
watch icon13

+ 27 other calls in file

22
23
24
25
26
27
28
29
30
31
var fs = require('fs');
var mac = require('../index.js');

var readdir = H.wrapCallback(fs.readdir);
var readFile = H.wrapCallback(fs.readFile);
var writeFile = H.wrapCallback(fs.writeFile);

var playback = new mac.Playback(0, mac.bmdModeHD1080i50, mac.bmdFormat10BitYUV);

var rootFolder = 'E:/media/EBU_test_sets/filexchange.ebu.ch/EBU test sets - Creative Commons (BY-NC-ND)/HDTV test sequences/1080i25/';
fork icon19
star icon92
watch icon13

+ 17 other calls in file

How does highland.wrapCallback work?

highland.wrapCallback is a function that takes a Node.js-style callback function and returns a new function that returns a Highland stream instead of calling the original callback directly. When the new function is called, it passes any arguments received to the original callback and emits the result as a single value in the Highland stream.

23
24
25
26
27
28
29
30
31
32
const elementsURL = 'https://registry.smpte-ra.org/view/published/Elements.xml';
const labelsURL = 'https://registry.smpte-ra.org/view/published/Labels.xml';

const http = (groupsURL.startsWith('https')) ? require('https') : require('http');

const gzip = H.wrapCallback(zlib.gzip);
const writeFile = H.wrapCallback(fs.writeFile);

var ulCache = {};
var memberOf = {};
fork icon2
star icon17
watch icon8

+ 5 other calls in file

3
4
5
6
7
8
9
10
11
12
var objectPath = require('object-path');
var format = require('util').format;

var YQL_API = 'http://query.yahooapis.com/v1/public/yql';

var getGot = _.wrapCallback(got);

var slice = Array.prototype.slice;

var isString = function(val) {
fork icon2
star icon15
watch icon4

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const highland = require("highland");

// Define a function that accepts a callback and returns the result using the callback
function asyncFunc(param1, param2, callback) {
  setTimeout(() => {
    if (param1 === "error") {
      callback(new Error("Something went wrong!"), null);
    } else {
      callback(null, `${param1}-${param2}`);
    }
  }, 1000);
}

// Use wrapCallback to convert the async function to a stream that can be piped
const stream = highland.wrapCallback(asyncFunc);

// Call the stream with parameters and handle the result
stream("hello", "world")
  .each((result) => console.log(result))
  .errors((err) => console.error(err));

In this example, asyncFunc is a function that takes two parameters and a callback. It returns the result using the callback in a Node.js-style callback pattern. highland.wrapCallback is used to convert asyncFunc to a Highland.js stream, which can be piped and manipulated like any other Highland.js stream. The stream is then called with the parameters hello and world, and the result is printed to the console using console.log. If an error occurs, it is printed to the console using console.error.

8
9
10
11
12
13
14
15
16
function Graphmalizer (userConfig) {
  // store configuration with user overrides
  var conf = config(userConfig)

  // setup neo4j client
  var batchCommit = H.wrapCallback(neoBatch(conf.Neo4J))

  // setup input checker '~ schema validation'
  var checkInput = inputChecker(conf.types)
fork icon1
star icon0
watch icon7

+ 3 other calls in file

94
95
96
97
98
99
100
101
102
103
    }))
};

return H([getStackInputs(inputKeys)])
  .doto(log('processed input: synchronous'))
  .flatMap(({ Template, ...inputs }) => H.wrapCallback(fs.readFile)(Template)
    .map(body => body.toString('utf8'))
    .map(TemplateBody => ({
      ...inputs,
      TemplateBody
fork icon1
star icon0
watch icon1

136
137
138
139
140
141
142
143
144
145

if (config.recordType === 'table') return flushLookupTable(stream, config);
if (config.recordType === 'export') return exportEvents(stream, config);
if (config.recordType === 'peopleExport') return exportProfiles(stream, config);

const flush = _.wrapCallback(callbackify(flushToMixpanel));

const mpPipeline = _.pipeline(
	// * transforms
	_.map((data) => {
fork icon0
star icon13
watch icon6

+ 115 other calls in file

4
5
6
7
8
9
10
11
12
13
14
var execStreaming = highland.wrapCallback(exec);


module.exports = {
  checkout: highland.wrapCallback(git.checkout),
  merge: highland.wrapCallback(git.merge),
  push: highland.wrapCallback(git.push),
  status: highland.wrapCallback(git.status),
  createTag: highland.wrapCallback(git.tag),
  readTags: execStreaming('git tag')
            .split('\r')
fork icon1
star icon4
watch icon5

+ 5 other calls in file

95
96
97
98
99
100
101
102
103
104
105
  });
}


function launch(preferredPort) {
  return getFreePort(preferredPort).flatMap(function(port) {
    var seleniumServerStream = highland.wrapCallback(selenium)({stdio: 'pipe'})
    .errors(function(err) {
      console.log('seleniumServer error');
      console.log(err);
    })
fork icon1
star icon4
watch icon5

+ 2 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17
  root: __dirname + '/../../',
  showDir: true,
  autoIndex: true
});


var getFreePort = highland.wrapCallback(freeport);


/*
function getPort(preferredPort) {
  return highland([preferredPort])
fork icon1
star icon4
watch icon5

54
55
56
57
58
59
60
61
62
  return path.join(__dirname, this._path, f);
};

Client.prototype.build = function build(callback) {
  var that = this;
  var readFile = _.wrapCallback(fs.readFile);

  // None of these actions are actually executed
  // until something comes along to 'thunk' it
fork icon0
star icon5
watch icon2

7
8
9
10
11
12
13
14
15
16
17
const errors = require('restify-errors')
const expire = 1 * 60 * 60 * 24 * 7 * 52


module.exports.checkRedis = redis => type => match => otherwise => {
  const key = `transitland:${type}:${match}`.replace(/ /g, '')
  return h.wrapCallback(redis.get.bind(redis))(key)
    .compact()
    .map(JSON.parse)
    .otherwise(otherwise)
    .compact()
fork icon0
star icon1
watch icon0

+ 5 other calls in file

0
1
2
3
4
5
6
7
8
9
10
11
12
const _ = require('highland');
const glob = require('glob');
const fs = require('fs');
const R = require('ramda');


const readFile = _.wrapCallback(fs.readFile);


const inputStream = (filePatterns) => {


  const paths = R.chain(glob.sync, filePatterns);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

39
40
41
42
43
44
45
46
47
48

opt.uri = '/projects';

let globalArray = [];

const requestStream = H.wrapCallback(request);

const checkBounderies = (htmlBody) => {
    const body = JSON.parse(htmlBody);
    if (!_.get('isLastPage')(body)) {
fork icon0
star icon0
watch icon2

+ 5 other calls in file