How to use the baconjs.fromNodeCallback function in baconjs

To help you get started, we’ve selected a few baconjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github viddo / atom-textual-velocity / lib / path-watcher-factory.js View on Github external
.flatMap((fileReader: FileReaderType) => {
              const readResult: FileReaderResultType = {
                filename: filename,
                notePropName: fileReader.notePropName,
                value: null
              }
              return Bacon
                .fromNodeCallback(fileReader.read.bind(fileReader), notesPath.fullPath(filename), fileStats)
                .map(value => {
                  readResult.value = value === undefined ? null : value // make sure value cannot be undefined
                  return readResult
                })
                .mapError(err => {
                  console.warn('failed to read file:', err)
                  return readResult
                })
            })
        })
github CleverCloud / clever-tools / src / models / app_configuration.js View on Github external
function loadApplicationConf (ignoreParentConfig = false, pathToFolder) {
  if (pathToFolder == null) {
    pathToFolder = path.dirname(conf.APP_CONFIGURATION_FILE);
  }
  const fileName = path.basename(conf.APP_CONFIGURATION_FILE);
  const fullPath = path.join(pathToFolder, fileName);
  Logger.debug('Loading app configuration from ' + fullPath);
  return Bacon.fromNodeCallback(fs.readFile, fullPath)
    .flatMapLatest(Bacon.try(JSON.parse))
    .flatMapError((error) => {
      Logger.info('Cannot load app configuration from ' + conf.APP_CONFIGURATION_FILE + ' (' + error + ')');
      if (ignoreParentConfig || path.parse(pathToFolder).root === pathToFolder) {
        return { apps: [] };
      }
      return loadApplicationConf(ignoreParentConfig, path.normalize(path.join(pathToFolder, '..')));
    });
};
github raimohanska / turtle-roy / turtlestore.js View on Github external
function mongoFind(query) {
    return Bacon.fromNodeCallback(turtles.find(query).limit(100).sort({date: -1}), "toArray")
  }
  function sendResult(resultE, res) {
github raimohanska / turtle-roy / turtlestore.js View on Github external
function mongoPost(data) {
    return Bacon.fromNodeCallback(turtles, "insert", [data])
  }
  function mongoFind(query) {
github heikkipora / registry-sync / index.js View on Github external
function fetchUrl(url, bodyIsBinary) {
  if (responseCache[url]) {
    return Bacon.later(0, responseCache[url])
  }

  return Bacon.fromNodeCallback((callback) => {
    request(url, { timeout: 20000, encoding: bodyIsBinary ? null : undefined }, (error, response, body) => {
      if (!error && response.statusCode == 200) {
        if (!url.endsWith('.tgz')) {
          responseCache[url] = body
        }
        callback(null, body)
      } else {
        const statusCode = response ? response.statusCode : 'n/a'
        callback(`Failed to fetch ${url} because of error '${error}' and/or HTTP status ${statusCode}`)
      }
    })
  })
}
github ayasin / frhttp / lib / writer.js View on Github external
}).flatMap(function (input) {
		return Bacon.fromNodeCallback(fs.open, input.name, 'r').map(function (fd) {
			return {
				fd: fd,
				size: input.size,
				read: 0
			};
		});
	}).onValue(function (input) {
		readerStream.push(input);
github viddo / atom-textual-velocity / lib / project.js View on Github external
.flatMap(({path}) => {
          return Bacon
            .fromNodeCallback(this.darwin.getTags, path)
            .map(([tags]) => ({
              path: path,
              tags: tags.join(' ')
            }))
        })
        .filter(R.is(Object))