Rajeshwar
Rajeshwar

Reputation: 11661

Is it possible to get strand count?

I currently have a strand that perform jobs for me in a linear order. I wanted to know if there was a way to get the no. of jobs in the queue of the strand.

Upvotes: 3

Views: 224

Answers (1)

Tanner Sansbury
Tanner Sansbury

Reputation: 51941

There is no easy way as strand neither provides a public means to access the information nor directly contains a count. If you access the private member variables, then it would be possible to obtain the size via count_ within strand::impl_.

Alternative approaches include:

  • Wrapping the strand, providing a similar API that increments and decrements counts. This new type would need to wrap any handlers being posted, as it needs to inject a hook to decrementing the count once the user's handler finishes execution.
  • Create a functor object that increments a count during its construction, and decrements a count during destruction. All handlers being posted or dispatched through a strand would be wrapped by the functor.

Upvotes: 2

Related Questions