Giter Site home page Giter Site logo

Comments (4)

All8Up avatar All8Up commented on May 17, 2024 1

I have a functional solution to this now. Thanks.

Just to clarify though:

If I use it inside the current loop it will be blocking (of the other polled items) while the command is in progress?

It's possible I am misunderstanding, but it's still an async function, so conceptually everything else should be able to make progress, I'd say. But (and I am not sure I am understanding your sample code 100%), I'd think you may run into borrowing issues with respect to stream.

Sorry, to be more clear, if I used drive within the select which is supposed to be polling the data stream, I would not be polling the other streams, i.e. the order updates and the command channel, not to mention any data items that came in during the subscription change would be lost as mentioned below. While that would probably be fine in normal use, if I'm building a proxy for the streams, that would be rather bad to drop data and of course have the latency issues on the other channels.

What I was considering is spinning up two separate tasks: one for all the data stuff as I have it now and the other that takes the subscription portion from connect and simply resolves the future returned from subscribe. If I'm reading things correctly, as long as I await the future and the other task is still polling the stream, it should work?

I think so, yeah.

So, this does seemingly work, I'll know more when the actual market opens of course.

from apca.

d-e-s-o avatar d-e-s-o commented on May 17, 2024

Could you use drive function to resolve the future on the command dispatch path itself, i.e., in the Commands::ChangeSubscriptions handler block? Do you have the stream available there (I suppose you may into borrowing issues then, but not 100% sure)? It's not great, I agree, and certainly questionable if you intend to have high throughput in your proxy, but if I recall correctly it's all you will get.

Just conceptually (again, if I remember correctly), you can only ever have a single Subscription::subscribe operation in flight (which is kind of where the mut self comes from). The reason is that all it does in the background is to send a control message (request) over the stream and then wait for a control message response. From the Alpaca side, at least last I checked, there was no correlation between control message requests and responses, so we can't infer that this response belongs to that request and then dispatch accordingly. All we can say is that this is a control message that we just received, give it to the entity that made the last request. So in order to be correct, there can only be one requestor and all authenticate/subscribe/unsubscribe operations need to be serialized.

from apca.

All8Up avatar All8Up commented on May 17, 2024

I don't think that whatever I do will actually use the drive macro due to it requiring both the subscribe future and the mut stream. I.e. I can't use the drive macro outside of the current select because it needs the mut stream in addition to the future. If I use it inside the current loop it will be blocking (of the other polled items) while the command is in progress? (Also, I think any data messages that happen to show up get eaten? Wasn't sure about that bit.) What I was considering is spinning up two separate tasks: one for all the data stuff as I have it now and the other that takes the subscription portion from connect and simply resolves the future returned from subscribe. If I'm reading things correctly, as long as I await the future and the other task is still polling the stream, it should work?

from apca.

d-e-s-o avatar d-e-s-o commented on May 17, 2024

I don't think that whatever I do will actually use the drive macro due to it requiring both the subscribe future and the mut stream.

Fair enough. Your use case is different than what it was designed for.

If I use it inside the current loop it will be blocking (of the other polled items) while the command is in progress?

It's possible I am misunderstanding, but it's still an async function, so conceptually everything else should be able to make progress, I'd say. But (and I am not sure I am understanding your sample code 100%), I'd think you may run into borrowing issues with respect to stream.

(Also, I think any data messages that happen to show up get eaten? Wasn't sure about that bit.)

Yep. I thought the documentation made that clear, but looking at it I don't see it mentioned either...

What I was considering is spinning up two separate tasks: one for all the data stuff as I have it now and the other that takes the subscription portion from connect and simply resolves the future returned from subscribe. If I'm reading things correctly, as long as I await the future and the other task is still polling the stream, it should work?

I think so, yeah.

from apca.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.