简体   繁体   English

使用流结束NodeJS程序

[英]End NodeJS program using streams

I have a small program that is running an ETL pipeline on some XML data. 我有一个小程序在一些XML数据上运行ETL管道。 I'm using pump ( package ) to combine a Readable , Duplex , and Writeable streams. 我使用的pump )的结合ReadableDuplex ,和Writeable流。 I'm getting the final 'done' callback, but the program doesn't exit. 我正在进行最后的'完成'回调,但程序没有退出。 Is the only way to handle this to call process.exit(0) ? 处理此问题的唯一方法是调用process.exit(0)吗?

Here's the code snippet: 这是代码片段:

pump(
    fileStream,
    parser,
    inserter,
    (err) => {
        if (err) {
            console.log(err);
        } else {
            console.log('done');
        }
    });

Edit: Just to close the loop, what @FakeFootball suggested does the trick: 编辑:只是为了关闭循环,@ FakeFootball建议的诀窍是:

pump(
        fileStream,
        parser,
        inserter,
        (err) => {
            if (err) {
                console.log(err);
            } else {
                parser.destroy();
                inserter.destroy();
                fileStream.destroy();
            }
        });

Without seeing the rest of your code, my guess is you aren't closing/destroying any of your streams so they are still active. 在没有看到你的其余代码的情况下,我的猜测是你没有关闭/销毁任何你的流,所以它们仍然是活跃的。 Node won't close as it is still listening for potential actions on those streams. 节点不会关闭,因为它仍在侦听这些流上的潜在操作。 See the example in the usage section of the pump documentation for how they close the stream and it destroys the rest of them. 请参阅泵文档的使用部分中的示例,了解它们如何关闭流并破坏其余部分。 Pump usage 泵使用情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM