开始前preSS服务器之前等待几DB连接? [英] Wait for several db connections before starting express server?

查看:180
本文介绍了开始前preSS服务器之前等待几DB连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Ex preSS应用程序。在启动时它连接到一个Redis的服务器和一个PostgreSQL断绝。我想等到两个连接在启动前preSS服务器之前成功。现在,如果我在等待的只是有一个的回调,我认为回调中启动防爆preSS服务器。但如何在一个以上的异步操作时,等待最好做到这一点?我是新来这个。有没有做这样的事情一个很好的惯用模式?也许分组承诺在一起,或...?

I'm working on an Express app. At startup it connects to a Redis server and to a PostgreSQL sever. I'd like to wait for both connections to succeed before starting the express server. Now, if I were waiting on just one callback, I could initiate the Express server within that callback. But how to best do this when waiting on more than one async operation? I'm new to this. Is there a good idiomatic pattern for doing this sort of thing? Maybe grouping promises together or..?

推荐答案

承诺是你想要的。

您可以使用。所有()许诺等他们都完成的阵列上。你没有提到你使用的是什么无极库,但它是相当普遍的。这里的蓝鸟文档: https://github.com/ petkaantonov /蓝鸟/ BLOB /主/ API.md#---所有承诺

You can use .all() on an array of promises to wait for them all to complete. You didn't mention what Promise library you're using, but it's fairly universal. here's the Bluebird documentation: https://github.com/petkaantonov/bluebird/blob/master/API.md#all---promise

这篇关于开始前preSS服务器之前等待几DB连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆