getTotalFeatureCount() always 0

I need to count the number of features in a specfic layer for use later in my app.

APPROACH:

After my map's getLoadStatus() returns "LOADED", I iterate through my map's layers. When the appropriate layer is found I cast the layer to a FeatureLayer, then get the feature table and count of items in that table. Code below:

'getTotalFeatureCount()' always returns 0 at runtime, but when I set a breakpoint and step through the code I get the expected feature count for the layer of interest. Is there some race condition with counting?

QUESTION:

What am I doing wrong? Is there a better way to count the number of features having a non-zero attribute value in a specific map layer?