PelionIoT / mbed-connector-api-python

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

Make Asynch calls Blocking #2

Open BlackstoneEngineering opened 8 years ago

BlackstoneEngineering commented 8 years ago

@janjongboom : has expressed that the async calls should be blocking by default to be more pythonic.

This would eliminate the current need for

while not e.isDone()
    None

which amounts to 2 lines per api use.

janjongboom commented 8 years ago

It's more lines actually:

        e = connector.getResourceValue(id, KNOCK_RESOURCE)
        while not e.result and not e.error:
            None
        if e.error:
            raise Error(e.error)
        return e.result

vs.

     return connector.getResourceValue(id, bla)
BlackstoneEngineering commented 8 years ago

While I like the idea it wont work for most of the connector API calls since many of them are asynchronous and not guaranteed to complete. I have seen it happen on multiple ocassions where I am given an Async ID by connector but nothing ever comes back for that Async ID. In this case your blocking implementation would either never return. If as a counter measure you implement a timeout then you risk timing out before the value is returned.

Do you have a proposed solution for this?