我的问题是我有一个流管道设置如下。
readableStream.pipe(transformStream).pipe(writableStream);
Run Code Online (Sandbox Code Playgroud)
我真的不想将可写流写入任何地方,我只是使用它,这样我的转换流的缓冲区就不会得到备份。如何使可写流写入空目的地?
我正在尝试加载和解析文件,但是在调用两个函数并返回promise的结果时遇到了一些麻烦.我正在使用蓝鸟的承诺.以下代码按预期工作:
run = function (filePath) {
return Promise.join(
fs.readFileAsync(filePath, 'utf8')
.then(parseFile.parse.bind(null, 'userKey')),
users.getUsersAsync(usersObj)
.then(users.modifyRec.bind(null, process.env.users))
).then(function (args) {
return runProc('run', args[0], args[1]);
....
Run Code Online (Sandbox Code Playgroud)
我已将该parseFile.parse功能划分为两种方法,parseFile.parse并且parseFile.getProp.parseFile.getProp应该从方法分割之前获取输出parseFile.parse并返回返回的内容parseFile.parse.这是我尝试使用这两个功能:
run = function (filePath) {
return Promise.join(
fs.readFileAsync(filePath, 'utf8')
.then(parseFile.parse.bind(null, 'userKey'))
.then(parseFile.getProp.bind(null,'key')),
users.getUsersAsync(usersObj)
.then(users.modifyRec.bind(null, process.env.users))
).then(function (args) {
return runProc('run', args[0], args[1]);
....
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我在这做错了什么?
UPDATE
var ymlParser = require('yamljs');
var ymlObj;
parse = function ( data) {
"use strict";
if (!ymlObj) {
ymlObj = …Run Code Online (Sandbox Code Playgroud) 如果我有类似的东西:
let x = 20;
var z = 20;
Run Code Online (Sandbox Code Playgroud)
将
x === z
Run Code Online (Sandbox Code Playgroud) 这是我的原始代码,它是使用jquery deferreds/promises的缓存
var templateCache = {};
var retrieve = function (templateURL) {
if (!templateCache[templateURL]) {
templateCache[templateURL] = $.get(templateURL);
}
return templateCache[templateURL];
};
Run Code Online (Sandbox Code Playgroud)
我想尝试将它改成一个衬垫,所以我做了
var templateCache = {};
var retrieve = function( templateURL ){
return templateCache[ templateURL ] || templateCache[ templateURL ] = $.get( templateURL );
}
Run Code Online (Sandbox Code Playgroud)
但我一直收到一个错误,即return语句的左侧无效
假设我正在使用一个揭示模块模式并具有嵌套函数,如:
function outer () {
function a () {}
function b () {}
function c () {}
}
Run Code Online (Sandbox Code Playgroud)
我可以用对象简写来揭示这些函数:
return { a, b, c };
或者我是否需要将它们绑定到变量,如:
var a = function a () {};
var b = function b () {};
Run Code Online (Sandbox Code Playgroud) javascript ×5
ecmascript-6 ×2
node.js ×2
bluebird ×1
caching ×1
jquery ×1
object ×1
promise ×1
return ×1
stream ×1