首页 \ 问答 \ 等待完成异步操作(Waiting for completing of asynchronous operations)

等待完成异步操作(Waiting for completing of asynchronous operations)

大家好!

有一个io_service对象,方法run()在线程池中工作。 有一组类,使用ip :: tcp :: socket进行异步写入。 我需要阻止这类类的析构函数,直到他的任务存在于io_service的队列中。 例如,添加方法join()。 但是阻止析构函数的原因是什么?


HI all!

There is an io_service object, methods run() works in a thread pool. There are set of classes, which make async write using ip::tcp::socket. I need to block destructor of this kind of class, until his tasks live in the io_service's queue. In example, to add method join(). But what the reason to block the destructor?


原文:https://stackoverflow.com/questions/5389794
更新时间:2021-12-15 12:12

最满意答案

这就是我所做的,实际上是在javascript中:

function forall (obj, key, func) {
    if (func) func(obj, key);
    var item = obj[key];
    if (item instanceof Object || item instanceof Array) {
        for (var k in item) {
            forall(item, k, func);
        }
    }
}


forall(obj, key, function(obj, key) {
    console.log('object:'+ obj +'['+key+'] = '+ obj[key]);
});

This is what I've done, actually in javascript:

function forall (obj, key, func) {
    if (func) func(obj, key);
    var item = obj[key];
    if (item instanceof Object || item instanceof Array) {
        for (var k in item) {
            forall(item, k, func);
        }
    }
}


forall(obj, key, function(obj, key) {
    console.log('object:'+ obj +'['+key+'] = '+ obj[key]);
});

相关问答

更多
  • JavaScript json变量是否正确填充(即,您的控制台显示了什么?)可能您必须在发布之前将json变量编码为字符串。 即:而不是data: "func=parse&json="+json,使用data: "func=parse&json="+JSON.stringify(json), Is the javascript json variable correctly filled (i.e. what does your console show you?) Possible you must en ...
  • 它是一个数组,所以answer[0].companyName会获取数组中的第一个对象,然后是companyName属性。 It's an array, so answer[0].companyName gets you the first object in the array, and then the companyName property.
  • 尝试这个 : $response = json_encode(array('code'=>'0','id'=>$id,'usr'=>$usr, 'everything'=>$ary)); 它将完美适合您。 a better way to do this is to use the implode function in php to convert the arrays in to strings and then pass it $everything= array($ary); ConvertEve ...
  • 标题和描述在子元素“book_details”中,这是一个数组本身 应该 $r['book_details'][0]['title'] 和 $r['book_details'][0]['description'] 只需在PHP中打开错误报告,应该很明显,您尝试访问的索引不存在。 更新:添加了数组索引 title and description are inside a sub-element "book_details", which is an array itself should be $r['b ...
  • 你的代码有几个问题:试试这个(未经测试):