我正在开发一个有角度的项目,我遇到了使用可观察对象调用后端来获取产品的情况。
代码如下所示。
getProducts () : Product[] {
this.http.get<[]>(this.m_baseURL+'/products').subscribe(res => {
console.log(res)
this.products = res;
});
return this.products
}
Run Code Online (Sandbox Code Playgroud)
问题是,return 语句不会等待上述语句执行。在我的组件中,我得到一个空数组。我在服务和组件中使用控制台日志进行了检查。事实证明,return 语句是在 observable 完成赋值之前执行的。
我如何让它停止直到完成其工作,就像 async wait 一样。我应该使用普通的异步等待而不是可观察的吗?
这是我的第一个 Angular 项目,所以如果问题是新手,请原谅我。
我正在尝试使用 pip 安装 functools。但我收到以下错误。
Collecting functools
Using cached functools-0.5.tar.gz
Building wheels for collected packages: functools
Running setup.py bdist_wheel for functools ... error
Complete output from command c:\python35\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\TAUSEE~1\\AppData\\Local\\Temp\\pip-build-0gc470iw\\functools\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\TAUSEE~1\AppData\Local\Temp\tmpn0sob7vxpip-wheel- --python-tag cp35:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.5
copying functools.py -> build\lib.win-amd64-3.5
running build_ext
building '_functools' extension
creating build\temp.win-amd64-3.5
creating build\temp.win-amd64-3.5\Release
creating build\temp.win-amd64-3.5\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个线程,该线程使用 C++ 中的套接字处理客户端-服务器通信。
程序抛出错误
std::Invoke,找不到匹配的重载函数
错误 C2893 未能专门化函数模板 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'
我无法调试程序,因为它在启动时崩溃。
有两个参数的线程初始化有什么问题吗?或者我错过了一些图书馆,类导入?
任何人都可以帮助我,我在这里缺少什么?
这是我的代码
#include <ws2tcpip.h>
#include <iostream>
#include <string>
#include <thread>
using namespace std;
#pragma comment (lib, "Ws2_32.lib")
#define DEFAULT_BUFLEN 512
PCSTR IP_ADDRESS = "192.168.1.100";
#define DEFAULT_PORT "3504"
struct client_type
{
SOCKET socket;
int id;
char received_message[DEFAULT_BUFLEN];
};
int process_client(client_type& new_client);
int main();
int process_client(client_type& new_client)
{
while (1)
{
memset(new_client.received_message, 0, DEFAULT_BUFLEN);
if (new_client.socket != 0)
{
int iResult = recv(new_client.socket, new_client.received_message, DEFAULT_BUFLEN, 0);
if …Run Code Online (Sandbox Code Playgroud)