How to use the kew.nfcall function in kew

To help you get started, we’ve selected a few kew 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 sx1989827 / DOClever / node_modules / phantomjs-prebuilt / install.js View on Github external
return kew.nfcall(fs.remove, targetPath).then(function () {
    // Look for the extracted directory, so we can rename it.
    var files = fs.readdirSync(extractedPath)
    for (var i = 0; i < files.length; i++) {
      var file = path.join(extractedPath, files[i])
      if (fs.statSync(file).isDirectory() && file.indexOf(helper.version) != -1) {
        console.log('Copying extracted folder', file, '->', targetPath)
        return kew.nfcall(fs.move, file, targetPath)
      }
    }

    console.log('Could not find extracted file', files)
    throw new Error('Could not find extracted file')
  })
}
github volumio / Volumio2 / app / plugins / music_service / music_library / lib / utils.js View on Github external
return iterateArrayAsync(folderEntries, function(folderEntry) {
			var childLocation = path.join(location, folderEntry);

			// get stats
			return libQ.nfcall(fs.stat, childLocation).then(function(stats) {
				// 'Stats' are a little bit different from 'Dirent'
				stats.name = folderEntry;
				return stats;
			}).fail(function(err) {
				// skip errors
				console.log(err);
			});
		});
	});
github Medium / phantomjs / install.js View on Github external
function copyIntoPlace(extractedPath, targetPath) {
  console.log('Removing', targetPath)
  return kew.nfcall(fs.remove, targetPath).then(function () {
    // Look for the extracted directory, so we can rename it.
    var files = fs.readdirSync(extractedPath)
    for (var i = 0; i < files.length; i++) {
      var file = path.join(extractedPath, files[i])
      if (fs.statSync(file).isDirectory() && file.indexOf(helper.version) != -1) {
        console.log('Copying extracted folder', file, '->', targetPath)
        return kew.nfcall(fs.move, file, targetPath)
      }
    }

    console.log('Could not find extracted file', files)
    throw new Error('Could not find extracted file')
  })
}
github volumio / Volumio2 / app / metadatacache.js View on Github external
CoreMetadataCache.prototype.fetchAlbumArt = function(sMbid, sBasePath) {
	var self = this;
	var bufferImage = null;
	var sPath = '';

console.log('fetching art for ' + sMbid);
	return libQ.nfcall(libFast.bind(self.coverArtClient.release, self.coverArtClient), sMbid, {piece: 'front'})
		.then(function(out) {
			bufferImage = out.image;
			sPath = sBasePath + '/' + sMbid + out.extension;
console.log(sPath);
			return libQ.nfcall(libFileSystem.open, sPath, 'w');
		})
		.then(function(file) {
			return libQ.nfcall(libFileSystem.write, file, bufferImage, 0, 'binary');
		})
		.then(function(result) {
			console.log('file written');
			return sPath;
		})
		.fail(function(error) {
			// Have this clause to catch errors so the parent promise does not abort
			return sPath;
github tschaub / gulp-newer / index.js View on Github external
.spread(function(destStats, extraStats) {
      if ((destStats && destStats.isDirectory()) || self._ext || self._map) {
        // stat dest/relative file
        var relative = srcFile.relative;
        var ext = path.extname(relative);
        var destFileRelative = self._ext
          ? relative.substr(0, relative.length - ext.length) + self._ext
          : relative;
        if (self._map) {
          destFileRelative = self._map(destFileRelative);
        }
        var destFileJoined = self._dest
          ? path.join(self._dest, destFileRelative)
          : destFileRelative;
        return Q.all([Q.nfcall(fs.stat, destFileJoined), extraStats]);
      } else {
        // wait to see if any are newer, then pass through all
        if (!self._bufferedFiles) {
          self._bufferedFiles = [];
        }
        return [destStats, extraStats];
      }
    })
    .fail(function(err) {
github volumio / Volumio2 / app / plugins / music_service / mpd / index.js View on Github external
ControllerMpd.prototype.mpdEstablish = function () {
	var self = this;

	// TODO use names from the package.json instead
	self.servicename = 'mpd';
	self.displayname = 'MPD';

	//getting configuration

	// Save a reference to the parent commandRouter
	self.commandRouter = self.context.coreCommand;
	// Connect to MPD
	self.mpdConnect();

	// Make a promise for when the MPD connection is ready to receive events
	self.mpdReady = libQ.nfcall(self.clientMpd.on.bind(self.clientMpd), 'ready');

    self.mpdReady.then(function () {
        if (startup) {
            startup = false;
            self.checkUSBDrives();
            self.listAlbums();
        }
    })

	// Catch and log errors
	self.clientMpd.on('error', function (err) {
		self.logger.error('MPD error: ' + err);
		if (err = "{ [Error: This socket has been ended by the other party] code: 'EPIPE' }") {
			// Wait 5 seconds before trying to reconnect
			setTimeout(function () {
				self.mpdEstablish();
github volumio / Volumio2 / app / plugins / music_services / mpd / index.js View on Github external
self.servicename = 'mpd';
	self.displayname = 'MPD';

	//getting configuration
	var config=libFsExtra.readJsonSync(__dirname+'/config.json');
	var nHost=self.config.get('nHost');
	var nPort=self.config.get('nPort');

	// Save a reference to the parent commandRouter
	self.commandRouter = self.context.coreCommand;

	// Connect to MPD
	self.clientMpd = libMpd.connect({port: nPort, host: nHost});

	// Make a promise for when the MPD connection is ready to receive events
	self.mpdReady = libQ.nfcall(libFast.bind(self.clientMpd.on, self.clientMpd), 'ready');

	// Catch and log errors
	self.clientMpd.on('error', libFast.bind(self.pushError, self));

	// This tracks the the timestamp of the newest detected status change
	self.timeLatestUpdate = 0;
	self.updateQueue();
	self.fswatch();
	// When playback status changes
	self.clientMpd.on('system', function() {
		var timeStart = Date.now();

		self.logStart('MPD announces state update')
		.then(libFast.bind(self.getState, self))
		.then(libFast.bind(self.pushState, self))
		.fail(libFast.bind(self.pushError, self))
github volumio / Volumio2 / app / index.js View on Github external
CoreCommandRouter.prototype.i18nJson = function (dictionaryFile,defaultDictionaryFile,jsonFile) {
    var self=this;
    var methodDefer=libQ.defer();
    var defers=[];


	try {
		fs.readJsonSync(dictionaryFile);
	} catch(e) {
		dictionaryFile = defaultDictionaryFile;
	}

    defers.push(libQ.nfcall(fs.readJson,dictionaryFile));
    defers.push(libQ.nfcall(fs.readJson,defaultDictionaryFile));
    defers.push(libQ.nfcall(fs.readJson,jsonFile));

    libQ.all(defers).
            then(function(documents)
    {

        var dictionary=documents[0];
        var defaultDictionary=documents[1];
        var jsonFile=documents[2];

        self.translateKeys(jsonFile,dictionary,defaultDictionary);

        methodDefer.resolve(jsonFile);
    })
    .fail(function(err){
        self.logger.info("ERROR LOADING JSON "+err);
github volumio / Volumio2 / app / metadatacache.js View on Github external
.then(function() {
			if (sType === 'album') {
				return libQ.nfcall(libMusicBrainz.searchReleases, sValue, {});
			} else if (sType === 'artist') {
				return libQ.nfcall(libMusicBrainz.searchArtists, sValue, {});
			}
		})
		.then(function(arrayResults) {
github volumio / Volumio2 / app / plugins / music_services / spop / index.js View on Github external
.then(function() {
		self.commandRouter.pushConsoleMessage('Storing Spop tracklist in db...');

		var ops = [
			{type: 'put', key: 'tracklist', value: self.tracklist}
		];

		return libQ.nfcall(libFast.bind(dbTracklist.batch, dbTracklist), ops);
	})
	.then(function() {

kew

a lightweight promise library for node

Apache-2.0
Latest version published 9 years ago

Package Health Score

59 / 100
Full package analysis