How to wait for a CallResult from Steamworks.NET? I can't just =>

For example, to get an AuthTicket, I have these

private CallResult<NumberOfCurrentPlayers_t> m_NumberOfCurrentPlayers;
private Callback<GetAuthSessionTicketResponse_t> m_GetAuthSessionTicketResponse;

then OnEnable():

m_NumberOfCurrentPlayers = CallResult<NumberOfCurrentPlayers_t>.Create(OnNumberOfCurrentPlayers);
m_GetAuthSessionTicketResponse = Callback<GetAuthSessionTicketResponse_t>.Create(OnGetAuthSessionTicketResponse);

So when I finally make the call:

public string GetAuthSessionTicket()
{
    // ...
    hTicket = SteamUser.GetAuthSessionTicket(ticketBlob, ticketBlob.Length, out ticketSize); // Triggers OnGetAuthSessionTicketResponse to be called shortly

    return "NotReadyYet" // I have to wait for callback! How do I do this? Normally I can just (result) => but I can't for this situation (that I know of).
}

private void OnGetAuthSessionTicketResponse(GetAuthSessionTicketResponse_t callback)
{
    Debug.Log("ticket == " + callback.hTicket + " / " + callback.eResult );
    // NOW I have the real value ... but how do I possibly return?
}

Well, if the request is asynchronous you can’t just make is synchronous without blocking the main thread. If the callback is synchronous (if it’s called from within the “GetAuthSessionTicket” method) you could use a lambda expression which you assign to the callback just before you call “GetAuthSessionTicket”.

However even i never worked with the Steamworks API, it looks like the callback doesn’t provide any “new” information. The callback just has the ticket handle which is already returned by “GetAuthSessionTicket”. If you look at this example i’ve found you actually don’t care much about the ticket handle, but about your “ticketBlob” and “ticketSize” which are filled / set immediately by the “GetAuthSessionTicket” method.

I’m not sure why you want to return a string. The ticket seems to be a binary blob. Of course you could encode the first “ticketSize” bytes from the ticketBlob as hex or base64 string, but whenever you need to use the ticket you have to convert it back. So it would make more sense to just keep the ticketBlob / ticketSize as it is. If you don’t want to “waste” memory you could “shorten” the array to the length of ticketSize. This could be done with Array.Resize(ref ticketBlob, ticketSize); or by creating a new array with the length of ticketSize and copy over the data. Having the ticketBlob size adjusted would mean you don’t need to store the ticketSize seperately.