Hi Gravin:

>The compiler will build the code for a lambda only once regardless of 
>how many times it's called. But it also won't let you create a 
>recursive lambda, which is what you would need if you wanted to have a 
>read operation repeat itself when it completes (which is the most common 
>case). 

I supposed that which would be built once durning compiling time but multi time in running time, wasn't it ?

It will implement every time when async_xxx be invoded. Although I was not do test for proving that.

 

 

>Well, actually that's not quite true -- you can type-erase a lambda via 
>std::function or similar and then call it recursively. But AFAIK you 
>can only do this when capturing by reference, and you can't safely do 
>that with a locally declared lambda when making async calls. So it's 
>not really useful in this context. 

 
Private member function or std::function type various and transmitted as reference could be better in this case.


>> It's better that build a function object in static. What do you think ? 

>Function objects have a similar lifetime issue, and making one static is 
>potentially dangerous if you could have multiple operations or 
>connections running concurrently. It's usually simplest to use a 
>private method of the containing class, which is what most of the 
>example code does. 

You are right, the static is dangerous in multiple op and concurrence, Thanks.


(If you really want to hide it from clients of your class, then use the 
PIMPL idiom.) 

 

 

Cheer~
 
程墨
PBI—北京加维通讯电子技术有限公司
地址:北京市海淀区西北旺镇 丰智东路3号院
邮编:100094