Async Operations in Server plugins

What is recommended for use in server plugins for asynchronous web operations?

I have analytics functions that get sent out to playfab for various things, and I'm currently using ThreadPool.QueueUserWorkItem. Is there a preferred method for fire and forget async operations such as these that would be friendlier to the server?

Comments

  • edited December 2017
    https://doc.photonengine.com/en-us/onpremise/current/plugins/manual#http
    I guess you want to do something similar, it's pretty cool how we can defer execution and resume later with info.Defer and info.Continue

    But i'm curious about async/awaits with photon, will it work just fine? For example in custom peer i want to do something async, wont it break if peer gets destroyed?

    How it works with photon's queues? Won't it create unexpected behavior? I can't write code for a little while, so i can just ask questions and read docs :(
  • Ideally the solution would not involve re-implementing the playfab SDK in order to put it through Photons HTTP mechanism.
  • hi, @JeremyS

    >What is recommended for use in server plugins for asynchronous web operations?
    you may use Async http requests. Just provide empty call back for it

    sdk update will contain new method called 'Enqueue' to enqueue task to rooms fiber. But your way is also fine. if there is not need to access some shared data. it will work just fine

    @TomatoFromTheSky with async/await because when your callback(rest of the method) will be called in will be called from arbitrary thread pool thread. in such a way you lose thread safety. the only way to get it working is peers fiber like this
    {// method begins
    ....some code...
    await .....;
    this.PeerFiber.Enqueue(....action code....);//this is the only instruction after await
    }// method ends

    best,
    ilya
  • Hi @chvetsov ,

    Has the 'Enqueue' method been implemented in the end?

    I am writing a Photon plug-in which calls PlayFab APIs. I need to marshal back the async results from those calls back to the fiber pool.
    'this.PeerFiber.Enqueue' you mentioned sounds like exactly what I need, but unfortunately I can't find PeerFiber property anywhere.

    As a workaround I am using:
    PluginHost.CreateOneTimeTimer(() => { ... }, 0).

    The question is, though, how safe is it? Can I access PluginHost from a background thread? What happens if the room gets shut down before the PluginHost.CreateOneTimeTimer() call?

    Thanks,
    Sylwester
  • hi, @Sly
    yes, it was. the issue is that we did not release this version of sdk yet

    best,
    ilya
Sign In or Register to comment.