How to use the when/pipeline function in when

To help you get started, we’ve selected a few when 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 particle-iot / particle-cli / src / app / cloud.js View on Github external
deviceId = undefined;
				onOff = false;
				break;
			case 'all':
				deviceId = undefined;
				break;
		}

		if (deviceId) {
			return cloudLib.signalDevice(deviceId, onOff)
				.then(() => {
					log.success(`${deviceId} is ${onOff ? 'shouting rainbows' : 'back to normal'}`);
				});
		}

		return pipeline([
			() => {
				if (deviceId) {
					return [deviceId];
				}

				return cloudLib.listDevices().then(devices => {
					return _.chain(devices).filter('connected').map('id').value();
				});
			},
			(deviceIds) => {
				return when.settle(deviceIds.map(id => {
					return cloudLib.signalDevice(id, onOff).catch(err => {
						const errors = err && err.body && err.body.errors;
						return when.reject(errors || err);
					});
				}));
github particle-iot / particle-cli / src / lib / library.js View on Github external
addLibraryToProject(library) {
		return pipeline([
			() => this.site.addedLibrary(library.name, library.version),
			() => this.projectProperties.addDependency(library.name, library.version)
		]);
	}
github particle-iot / particle-cli / src / app / cloud.js View on Github external
compileCode(opts) {
		const downloadPath = path.resolve(opts.saveTo || `${opts.deviceType}_firmware_${Date.now()}.bin`);

		return pipeline([
			() => {
				return whenNode.lift(fs.stat)(downloadPath).then(() => {
					log.silly(`Deleting ${downloadPath} before download`);
					return whenNode.lift(fs.unlink)(downloadPath);
				}, () => {});
			},
			() => {
				return ui.spin(cloudLib.compileCode(opts), 'Compiling');
			},
			(resp) => {
				return ui.spin(cloudLib.downloadFirmwareBinary(resp.binary_id, downloadPath), `Downloading to ${downloadPath}`)
					.then(() => {
						log.success(`Downloaded to ${downloadPath}`);
						log.info(resp.sizeInfo);
					});
			}
github particle-iot / particle-cli / src / cmd / library_migrate.js View on Github external
processLibrary(repo, libname, state, site, libdir) {
		return resultError(pipeline([
			() => repo.getLibraryLayout(libname),
			(layout) => {
				if (layout === 2) {
					return false;
				} else {
					return repo.setLibraryLayout(libname, 2)
						.then(() => {
							if (site.isAdaptersRequired()) {
								return buildAdapters(libdir, libname);
							}
						})
						.then(() => true);
				}
			}
		]));
	}
github particle-iot / particle-cli / src / cmd / library.js View on Github external
run(state, site) {
		this.site = site;
		this.projectProperties = new ProjectProperties(this.site.projectDir());
		const lib = site.libraryIdent();
		if (lib.version === undefined) {
			lib.version = 'latest';
		}
		return pipeline([
			() => this.ensureProjectExists(),
			() => this.loadProject(),
			() => this.fetchLibrary(lib.name, lib.version),
			(library) => this.addLibraryToProject(library),
			() => this.saveProject()
		]);
	}
github particle-iot / particle-cli / src / cmd / library.js View on Github external
addLibraryToProject(library) {
		return pipeline([
			() => this.site.addedLibrary(library.name, library.version),
			() => this.projectProperties.addDependency(library.name, library.version)
		]);
	}
github particle-iot / particle-cli / src / app / cloud.js View on Github external
listDevices(opts) {
		return pipeline([
			() => {
				return ui.spin(cloudLib.listDevicesWithFunctionsAndVariables(opts.filter), 'Retrieving device functions and variables...');
			},
			(devices) => {
				if (devices.length === 0) {
					return log.info('No devices claimed to your account');
				}

				ui.render('deviceList', devices, { platformsById });
			}
		]).catch(UnauthorizedError, () => {
			log.error('Not logged in');
		});
	},
github particle-iot / particle-cli / src / lib / library.js View on Github external
processLibrary(repo, libname, state, site) {
		return resultError(pipeline([
			() => repo.getLibraryLayout(libname),
			(layout) => {
				if (layout === 2) {
					return false;
				} else {
					return repo.setLibraryLayout(libname, 2)
					.then(() => true);
				}
			}
		]));
	}
}
github particle-iot / particle-cli / src / lib / library.js View on Github external
run(site, { name, version = 'latest' } = {}) {
		this.site = site;
		this.projectProperties = new ProjectProperties(this.site.projectDir());
		return pipeline([
			() => this.ensureProjectExists(),
			() => this.loadProject(),
			() => this.fetchLibrary(name, version),
			(library) => this.addLibraryToProject(library),
			() => this.saveProject()
		]);
	}