简体   繁体   English

如何将带有缓冲区的 object 从插件发送到节点线程安全?

[英]How to send object with buffer from addon to node threadsafe?

I am trying to send an object from addon to node but get: no matching function for call to 'Napi::Object::New(Napi::Env&, Napi::Object&)' .我正在尝试将 object 从插件发送到节点,但得到: no matching function for call to 'Napi::Object::New(Napi::Env&, Napi::Object&)'

How can I achieve that.我怎样才能做到这一点。

Any help will be appreciated.任何帮助将不胜感激。 Below is the code in question.下面是有问题的代码。

std::shared_ptr<ThreadSafeCallback> callback = NULL; // declared globally // 全局声明

callback = std::make_shared<ThreadSafeCallback> (info[0].As<Function>());    
std::thread([callback]
{
    try
    {
          callback->call([result, data](Napi::Env env, std::vector<napi_value>& args){
          const unsigned char* t = reinterpret_cast<const unsigned char *>( "123" );
          Object obj = Object::New(env);
          obj.Set("name", "world");
          obj.Set("frame", (char *)t);
            args = { env.Undefined(), Napi::Object::New(env, obj) }; // faile here
            // would like to have {"name": test, frame: buf}
          });
    }
}).detach();

Just changed Napi::Object::New to Napi::Object::Value.刚刚将 Napi::Object::New 更改为 Napi::Object::Value。 Its in the docs, but somehow i missed it.它在文档中,但不知何故我错过了它。

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

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