Skip to content

gRPC Async Style Server/Client RPCs #2664

@Reag

Description

@Reag

Is your feature request related to a problem? Please describe.
One type of functionality that I would very much like is the ability to run async RPC calls with a result. This is a functionality that is present in many other RPC solutions (Such as gRPC or Magic Onion) that is missing in NGO. Being able to request the server perform some procedure and receive a result after a delay would very much simplify large amounts of administrative work that my game manager performs.

Describe the solution you'd like
I would very much like to be able to run a piece of code like this on a client:

public async void SaveSceneState(string saveName)
{
    SceneSaveResult saveResult = await SaveSceneState_ServerRPC(saveName);
    Debug.Log(saveResult);
}

Describe alternatives you've considered
Currently, I use some hodpodge of UniTaskCompletionSources and directional communication, like what is below:

public UniTask<SceneSaveResult> SaveScene(string saveName)
{
       .....
        _saveResult = new UniTaskCompletionSource<SceneSaveResult>();
        SaveSceneState_ServerRPC(saveName, sender);
        return await _saveResult.Task;
}

[ServerRpc(RequireOwnership = false)]
public SaveSceneState_ServerRPC(string saveName, ServerRpcParams param)
{
    ...
    ClientOperationComplete_ClientRPC(result, clientParam);
}

[ClientRpc]
public void ClientOperationComplete_ClientRPC(SceneSaveResult result, ClientRpcParams param)
{
       _saveResult.TrySetResult(result);
}

Additional context
This particular problem has occurred in several places in our code. We have a fairly large project with multiple developers working on it, and anything we can use to simplify code is very very welcome. The server itself is running headless with a gRPC port open to communicate with our data server. Occasionally , the client itself is actually using the headless server as a pass-through to this dataserver, which does operate with the pattern described above. Finally, I personally feel that having parity with other libraries that use RPCs is just good practice. My CTO (who is not a unity developer) was very confused when I explained that I cant await a RPC in NGO

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature, request or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions