如何解决从Node.js中的sftp客户端中删除事件侦听器
希望获得一些帮助。我是Nodejs的新手,想知道是否有可能删除此自定义事件发射器。我正在使用软件包“ ssh2-sftp-client”,代码运行良好,但是从节点控制台收到警告,
ui<-fluidPage(
titlePanel('Minimal example'),tabsetPanel(
tabPanel("Example",#summary
sidebarPanel(width = 4,h5("The default interval for the analysis refresh is 5 minutes. If you wish to change this,please do so in the Box below:"),numericInput("intervaltime","Input refresh interval:",5),br(),h5("Press 'Run Analysis' button below to start automated analysis"),actionButton("automatedanalysis","Run Analysis")),mainPanel(
h4("An example plot"),plotOutput("example_plot",width = "100%"),h4("Some text with updated system time"),textoutput("example_text")
)
)))
server<-function(input,output,session){
observeEvent(input$automatedanalysis,{
interval=input$intervaltime*60
repeat{
currenttime<-Sys.time()
p<-ggplot(mpg,aes(displ,hwy,colour = class)) +
geom_point()+ggtitle(paste0("graph made at: ",currenttime))# adds on the current time
output$example_plot<-renderPlot({
return(p)
})
output$example_text<-renderText({
print(paste0("The current system time is: ",Sys.time())) #a check to kNow that it is working
})
Sys.sleep(interval)
}
})
}
shinyApp(ui,server)
但是我不确定在哪里整理活动,希望有人能给我一些建议。
(node:67350) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Client]. Use emitter.setMaxListeners() to increase limit
解决方法
两天以来一直在运行同样的问题。
使用 @supercharge/promise-pool 挽救了我的生命。
const { results,errors } = await PromisePool //Promise pool return an object containing these 2 properties where results = your promises responses as array
.for(myArrayOfData) // Your data array for iteration that will pass each value to your process
.withConcurrency(9) // Maximum amount of promises running at the same time
.process(async currentObject=> { return await myPromisedFunction(currentObject);}) // your promise execution
个人注意,由于它是由 SFTP 事件侦听器引起的警告,因此我将 withConcurrency()
设置为 9 因为我首先列出了创建 1 的远程文件夹中的所有文件 侦听器,+ 9 concurent 承诺获取每个文件内容,其中所有侦听器也是如此,总共 10,这是最大默认限制。
我的案例的完整示例:
client.list(CONFIG.sftp.folder).then(async (data) => {
const { results,errors } = await PromisePool
.for(data)
.withConcurrency(9)
.process(async sftpFileObject => { let file = await readFileContent(client,CONFIG.sftp.folder,sftpFileObject); return file; })
//Do some fun stuff with my results var containing my resolved data
resolve('Successfully pulled all file content without warning!')
}).then(() => {
client.end();
}).catch((err) => {
client.end();
console.error(err);
reject(err)
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。