Sha256: 8b6ae373113d01a1ca62965fcbbf9b28827a4e2a52f108dedb38f3e86e6c1b7a
Contents?: true
Size: 1.37 KB
Versions: 110
Compression:
Stored size: 1.37 KB
Contents
'use strict'; var _ = require('lodash'); var rx = require('rx-lite'); var runAsync = require('run-async'); /** * Create an oversable returning the result of a function runned in sync or async mode. * @param {Function} func Function to run * @return {rx.Observable} Observable emitting when value is known */ exports.createObservableFromAsync = function (func) { return rx.Observable.defer(function () { return rx.Observable.create(function (obs) { runAsync(func, function (value) { obs.onNext(value); obs.onCompleted(); }); }); }); }; /** * Resolve a question property value if it is passed as a function. * This method will overwrite the property on the question object with the received value. * @param {Object} question - Question object * @param {String} prop - Property to fetch name * @param {Object} answers - Answers object * @...rest {Mixed} rest - Arguments to pass to `func` * @return {rx.Obsersable} - Observable emitting once value is known */ exports.fetchAsyncQuestionProperty = function (question, prop, answers) { if (!_.isFunction(question[prop])) { return rx.Observable.return(question); } return exports.createObservableFromAsync(function () { var done = this.async(); runAsync(question[prop], function (value) { question[prop] = value; done(question); }, answers); }); };
Version data entries
110 entries across 110 versions & 5 rubygems