简体   繁体   English

使用Node,Mysql和TypeScript解决承诺链

[英]Resolving a Promise Chain Using Node, Mysql, and TypeScript

I am working in node and typescript. 我正在节点和打字稿中工作。 I have a controller and a repository. 我有一个控制器和一个存储库。 I can log the data out all over the place EXCEPT at the return from the repo. 我可以在仓库回购之外的所有地方注销数据。 Of course, the controller gets back nothing. 当然,控制器什么也得不到。 Here are the pastebins: 这是粘贴框:

This is not the correct way to use Promises. 这不是使用Promises的正确方法。 The getUsers() method is called and returns before the Promise has a chance to resolve. 在Promise有机会解决之前,将调用getUsers()方法并返回。 The quickest way to fix it is to return the Promise from the getUsers() method or use async/await. 修复它的最快方法是从getUsers()方法返回Promise或使用async / await。 Essentially, all of the logic that you have to update the userModels value happens after the function has already returned an empty array. 本质上,您必须更新userModels值的所有逻辑都在函数已经返回空数组之后发生。

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

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