尝试在我的工兵项目上安装 Mongoose 后出现此问题
util.js:157
throw new ERR_INVALID_ARG_TYPE('superCtor', 'Function', superCtor);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "superCtor" argument must be of type function. Received undefined
at Object.inherits (util.js:157:11)
at Object.<anonymous> (<project path>\__sapper__\dev\server\server.js:140600:8)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'ERR_INVALID_ARG_TYPE'
}
> Server crashed
Run Code Online (Sandbox Code Playgroud)
<project path> 只是我的项目路径
我有一个理论,这是由于将服务器代码捆绑/缩小到单个文件(__sapper__/dev/server.js)中引起的,但不确定如何修复它。
我的服务器汇总配置,如果有帮助的话:
util.js:157
throw new ERR_INVALID_ARG_TYPE('superCtor', 'Function', superCtor);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "superCtor" argument must be of type function. Received …Run Code Online (Sandbox Code Playgroud) 我试图在异步函数运行完成后调用回调
这是我想做的一个例子:
import asyncio
async def asyncfunction():
print('Hello')
await asyncio.sleep(10)
print('World')
return 10
def callback(n):
print(f'The async function returned: {n}')
loop = asyncio.get_event_loop()
# Will block the print until everything is done
callback(loop.run_until_complete(asyncfunction()))
print('Hey')
Run Code Online (Sandbox Code Playgroud)
这是它的作用:
Hello
World
The async function returned: 10
Hey
Run Code Online (Sandbox Code Playgroud)
这就是我想要它做的
编辑:“嘿”的位置并不重要,只要它不必等待异步函数完成即可
Hello
Hey
World
The async function returned: 10
Run Code Online (Sandbox Code Playgroud)
编辑:经过一些测试,我找到了一种可以实现我想要的功能的方法,尽管我不知道这是否是最好的方法
Hello
World
The async function returned: 10
Hey
Run Code Online (Sandbox Code Playgroud) 我试图直接调用传递给模板的虚拟方法,但是,它变成了虚拟调用
class Test {
public:
virtual void func() {
printf("foo\n");
}
};
template <auto F, typename T>
void foo(T* instance) {
(instance->*F)();
}
int main() {
auto a = new Test;
a->Test::func(); // directly calls it
auto f = &Test::func;
(a->*f)(); // virtual call
foo<&Test::func>(a); // virtual call
}
Run Code Online (Sandbox Code Playgroud)
目的是foo<&Test::func>(a)做同样的事情a->Test::func()