Tag: 生锈

在Rust中是否有NodeJS的EventEmitterfunction?

我正在寻找一个中心的“对象”,多个任务可以“订阅”asynchronous更新消息。

节点FFI包装函数在同步使用时失败,但asynchronous工作

我试图用Node FFI来包装一个Rust库(暴露一个C API)。 我有以下代码包装两个函数。 一个是返回指针的“构造函数”。 另一个需要一个指针并返回Cstring。 var libcomm = ffi.Library('lib/c_api/target/debug/libcomm', { 'comm_address_for_content': ['pointer', ['string']], 'comm_address_to_str': ['string', ['pointer']] }); 当我使用comm_address_to_str的asynchronous调用时,响应是正确的。 但是,当我尝试使用同步样式调用该函数时,它将返回垃圾,或者非常非常less,正确的结果。 以下nodeunittesting将执行该场景: const comm = require("../").libcomm; exports.testAddressForContent = function (test) { const ptr = comm.comm_address_for_content('test'); const result = comm.comm_address_to_str(ptr); test.equal(result, 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'); // always fails console.log('sync', result); // random garbage comm.comm_address_to_str.async(ptr, function(err, result) { test.equal(result, 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'); // […]