我是节点和回调的新手。现在我正在使用async.waterfall搞乱视频,但由于某种原因,在我插入第二个函数后,该过程退出,' pipe,'在我的瀑布。我没有正确地称它为正确吗?
// Download the video from S3, get thumbnail, and upload to a different S3 bucket.
async.waterfall([
function download(next) {
// Download the video from S3 into a buffer.
s3.getObject({
Bucket: srcBucket,
Key: srcKey
},
next);
},
function pipe(next) {
// Download the video from S3 into a buffer.
console.log("pipe function started");
var params = {Bucket: srcBucket, Key: srcKey};
s3.getObject(params).createReadStream().pipe(file, next);
},
function upload(response, next) {
console.log("upload function started");
// Stream the transformed image to a different S3 bucket.
s3.putObject({
Bucket: dstBucket,
Key: dstKey,
Body: response.Body,
ContentType: response.ContentType
},
next);
}
], function (err) {
if (err) {
console.error(
'Unable to resize ' + srcBucket + '/' + srcKey +
' and upload to ' + dstBucket + '/' + dstKey +
' due to an error: ' + err
);
} else {
console.log(
'Successfully resized ' + srcBucket + '/' + srcKey +
' and uploaded to ' + dstBucket + '/' + dstKey
);
}
callback(null, "message");
}
);
答案 0 :(得分:2)
[EDITED]
你说你插入了>>> import theano
>>> import theano.tensor as T
>>> x = T.dvector('x')
>>> y = x ** 2
>>> J, updates = theano.scan(lambda i, y,x : T.grad(y[i], x), sequences=T.arange(y.shape[0]), non_sequences=[y,x])
>>> f = theano.function([x], J, updates=updates)
>>> f([4, 4])
array([[ 8., 0.],
[ 0., 8.]])
功能。因此,最初,在pipe
函数之后调用了upload(response, next)
函数。鉴于download
函数的签名,我们可以推测upload
函数大致以这种方式调用其download
函数:next
。因此,瀑布数组中next(null, response)
函数之后的任何函数都将传递2个参数:download
。
有关如何在任务之间传递数据的详细信息,请参阅waterfall的文档。
因此,您的代码的直接问题是(response, next)
实际上传递了2个参数:pipe()
,但您的代码只定义了一个参数:(response, next)
。因此,它试图将(next)
参数(一个对象)用作函数。
您还有其他问题,但如何解决这些问题取决于您要实现的目标。