PelionIoT / mbed-connector-api-python

python library for using connector.mbed.com
Apache License 2.0
2 stars 2 forks source link

getResourceValue response should wait for response #8

Open janjongboom opened 8 years ago

janjongboom commented 8 years ago

Current getResourceValue response holds in e.result:

{u'async-response-id': u'1479551637#38e7a161-1932-4da1-a76e-39e9999ad258@fc5bae18-72d8-4d16-a0d0-00608fa76464/accelerometer/0/last_knock'}
  1. Where is my value?! Apparently it doesn't wait until my response is back...
janjongboom commented 8 years ago

I think the trouble is that e.result gets filled with this, and then I exited too early. We should not store that value in result.

BlackstoneEngineering commented 8 years ago

That is done very much on purpose. You did not wait for e.isDone() nor did you check for e.error.

janjongboom commented 8 years ago

I don't agree on this behavior now. We change the value of e.result, which should be immutable. There either is a response or there isn't. What if I have some other work to do, and thus get back to this value 2s later, the result can be different than before.

We should use a different property than result for the asyncResponseId.

BlackstoneEngineering commented 8 years ago

If you try to read the result before e.isDone() is true then there is no guarantee what will be in e.result. I enabled this for debugging purposes. Likely use case being a user keeps requesting something, it never finishes (never isDOne == True), so to debug it is helpful to know what the async-response-id for that call was. Otherwise there is no good way to figure this out.

When the call completes then result is overwritten with the result.