ms-iot/virtual-shields-arduino

`VirtualShield::block()` needs clarification/correction

Closed this issue · 3 comments

VirtualShield::block() makes a peculiar call to VirtualShield::waitFor(). If it is used correctly, then the usage should be described in a comment; otherwise it is a bug and should be fixed.

The code in question is pasted below:

int block(int id, bool blocking, size_t timeout = WAITFOR_TIMEOUT, int waitForResultId = -1);
int VirtualShield::block(int id, bool blocking, size_t timeout, int watchForResultId)
{
    return allowAutoBlocking && blocking ? waitFor(id, timeout, watchForResultId) : id;
}

int waitFor(int id, size_t timeout = WAITFOR_TIMEOUT, bool asSuccess = true, int resultId = -1);

Can you explain fruther what you find peculiar? This reads fine for me.

I think there should be paren around the blocking ternary to be explicit about order of operations.

block() calls waitFor() with three parameters, which leaves the forth, resultId to be defaulted.

block()'s parameter waitForResultId is passed to the asSuccess parameter of waitFor(), while the resultId parameter is defaulted to -1

It is peculiar, because I would expect block()'s waitForResultId parameter to be passed to waitFor()'s resultId parameter.

Closing issue due to inactivity