question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subscribe to Fire and Forget async calls?

See original GitHub issue

Is there a way to Subscribe to a generic UniTask? For example, I don’t want to await a UniTask but I want to do something with the result when it’s complete.

private async UniTask<string> GetPlayerName()
{
    string playerName = await GetPlayerNameFromServer();
    return playerName;
}

private void Awake()
{
    GetPlayerName().Subscribe(name => PlayerPrefs.Set("playerName", name));
    // other initialization
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
lightjiaocommented, Sep 30, 2022

ContinueWith<T>() maybe help:

private void Awake()
{
    GetPlayerName().ContinueWith(name => PlayerPrefs.SetString("playerName", name)).Forget();
    // other initialization
}
0reactions
cckellycommented, Oct 3, 2022

I was just coming back here to callout ContinueWith, it has several useful overrides that make this work. Thanks all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper way to start and fire-and-forget asynchronous calls?
First, you need to decide whether you really want fire-and-forget. ... is only calling a single method - eliding async and await is...
Read more >
FIRE AND FORGET. — Asynchronous over Synchronous
This implies that you can make any number of calls, anytime without having to wait for a response. Simply “fire and forget”. Curious...
Read more >
C# "fire and forget" method
Starting sync code inside "async void" method will be executed on the same thread of the main thread. That's "Thread.Sleep(3000)" means.
Read more >
c# - Starting a fire and forget async method
Just fire the task without async/await. private void InitMethod(ServiceControl serviceControl) { if (serviceControl != null) { Task.Factory.
Read more >
Can I fire-and-forget an async method? : r/csharp
Put simply, I want to call an async method and not await it. I'm coming from a background of managing my own threads....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found