AS3 - How to do a synchronous load of an asynchronous call?

前端 未结 4 831
小鲜肉
小鲜肉 2020-12-21 22:52

I have a function that loads a user object from a web service asynchronously.

I wrap this function call in another function and make it synchronous.

For exam

4条回答
  •  生来不讨喜
    2020-12-21 23:30

    See my answer here:

    DDD and Asynchronous Repositories

    Flex and Flash Remoting is inherently asynchronous so fighting against that paradigm is going to give you a ton of trouble. Our service delegates return AsyncToken from every method and we've never had a problem with it.

    If you want to ensure that the application doesn't render a new view or perform some other logic until the result/fault comes back, you could do the following:

    1. Attach an event listener for a custom event that will invoke your "post result/fault code"
    2. Make the async call
    3. Handle the result/fault
    4. Dispatch the custom event to trigger your listener from #1

    Bear in mind this going to lead to a lot of annoying boilterplate code every time you make an async call. I would consider very carefully whether you really need a synchronous execution path.

提交回复
热议问题