小编Geo*_*ian的帖子

向异步瀑布添加异步函数

我正在尝试开发一个 NodeJS 应用程序,但它不会按预期执行。我想先执行 downloadIMG,然后执行 featureMatching 并继续执行,直到 for 循环终止。指导我以正确的方式重写代码。

for (var i=0; i<dbImgCount; i++) {
    (function(i) {
        async.waterfall([
            async function downloadIMG(done) {
                try {
                    var options = {
                        url:  FolderPath[i].FolderPath,
                        dest: '/home/ubuntu/imgCompare/'                
                    }
                    const { filename, image } =  await download.image(options);
                    image2 = 'image.jpg';
                    done(null, 'hi');
                } catch (e) {
                    console.error(e)
                }
            },
            async function featureMatching(a, done){
                const img1 = cv.imread(image1);
                const img = 'image.jpg';
                const img2 = cv.imread(img);
                const orbMatchesImg = matchFeatures({
                    img1,
                    img2,
                    detector: new cv.ORBDetector(),
                    matchFunc: cv.matchBruteForceHamming
                    }, …
Run Code Online (Sandbox Code Playgroud)

asynchronous node.js async-await

6
推荐指数
1
解决办法
6651
查看次数

标签 统计

async-await ×1

asynchronous ×1

node.js ×1