XRPL-Labs/xumm-sdk-py

async support for subscribed response.resolved() also dead links in the readme.md

Opened this issue · 6 comments

there seems to be a few dead links ...
one of which im trying to find,
the Async process after returning data in the callback function

as im trying to find a async example of the on_payload_event/subscription_callback

only one i could find is this non async,

    def subscription_callback(self, event):
            logging.info('Subscription Event data results: '.format(event['data']))
            if 'expired' in event['data'] or 'signed' in event['data']:
                # payload is resolved return the data
                return event['data']

trying to convert this to async, seems to fail, as it returns anything which ends subscription

Also it says in docs
If a callback function is not provided, the subscription will stay active until the <PayloadSubscription>.resolve() method is called manually, eg. based on handling <PayloadSubscription>.websocket.onmessage events.
but it errors out if you try to use response.websocket.onmessage
(have also tried many others that are there after i dir() like _on_message, but is always None)

Additionally, in the docs it states;
Alternatively, the (by the sdk.payload_subscribe() method) returned raw websocket can be used to listen for WebSocket onmessage events.
and sdk.payload_subscribe() also doesn't seem to be a thing ? if thats a typo, still doesn't show the working onmessage endpoint.

Just to be clear you want the callback to be async as well? What exactly are you doing in the callback? Can you share your full code and what you're attempting to achieve?

Just to be clear you want the callback to be async as well? What exactly are you doing in the callback? Can you share your full code and what you're attempting to achieve?

Having the awaiting await subscription.resolved() to be async, so when you "await" this it doesn't halt the code...
(The initially 'sdk.payload.subscribe(uuid, callback)' and its def callback works OK within its own asyncio thread)

And yes the code in the link you posted does work, but halts on the awaiting resolved()
I didn't initially realise...

I did try putting the resolved() in its own asyncio thread etc, but that didn't work (as its other coroutines that hold the code up, payload.py it errors/reports at)...

I can post code I have once home, in like 4+ hours...

Ok if you can make a simple example that will help and I will fix it to do what you want.

If you don't want it to await, then just remove the await subscription.resolved() etc, and handle everything in the callback... I think I made some examples long ago but never pushed them into the repo.

Ok if you can make a simple example that will help and I will fix it to do what you want.

If you don't want it to await, then just remove the await subscription.resolved() etc, and handle everything in the callback... I think I made some examples long ago but never pushed them into the repo.

Tbh it's more or less as the link you posted ...

I did want to keep it within the same function, (as its hard to reconnect to discord slash commands cleanly)
I did try and get suitable feedback from the subscription function, but wasn't able to find how to use the subscription.websocket.on_message as the docs (I did try dir() to try and find it but some seem to need undocumented arguments (json or a dict when I trial and errored a few)...

Ahh I figured this is discord bot. subscription.websocket.on_message is documented incorrectly I think. I will look into that.