Starcounter.Async 3.0.0

Extensions for Starcounter aiding async programming

Install-Package Starcounter.Async -Version 3.0.0
dotnet add package Starcounter.Async --version 3.0.0
<PackageReference Include="Starcounter.Async" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Starcounter.Async --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Starcounter.Async, 3.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Starcounter.Async as a Cake Addin
#addin nuget:?package=Starcounter.Async&version=3.0.0

// Install Starcounter.Async as a Cake Tool
#tool nuget:?package=Starcounter.Async&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Starcounter Async Extensions

Available on nuget: Install-Package Starcounter.Async -Version 1.0.0

To introduce asynchronicity in Starcounter TypedJSON view-model, you have to use callbacks and handle errors carefully:

public void Handle(Input.StartWorkTrigger input)
{
    this.IsBusy = true;
    Task.Run(LengthyJob)
        .ContinueWith(task => Session.ScheduleTask(Session.Current.SessionId,
        (Session session, string sessionId) => {
            // might happen if this code is executed after the session has been destroyed
            if (session == null)
            {
                return;
            }
            try
            {
                // if LengthyJob resulted in exception, it will be unwrapped here
                this.Result = task.Result;
            }
            catch (Exception e)
            {
                this.Result = "Error";
            }
            finally
            {
                this.IsBusy = false;
                // otherwise the changes won't be immediately visible to the client
                session.CalculatePatchAndPushOnWebSocket();
            }
        }));
}

This library allows you to simplify this code by using async-await

public void Handle(Input.StartWorkTrigger input)
{
    AsyncInputHandlers.Run(async () =>
    {
        this.IsBusy = true;
        try
        {
            this.Result = await LengthyJob();
        }
        catch(Exception e)
        {
            this.Result = "Error";
        }
        finally
        {
            this.IsBusy = false;
        }
    });
}

Starcounter Async Extensions

Available on nuget: Install-Package Starcounter.Async -Version 1.0.0

To introduce asynchronicity in Starcounter TypedJSON view-model, you have to use callbacks and handle errors carefully:

public void Handle(Input.StartWorkTrigger input)
{
    this.IsBusy = true;
    Task.Run(LengthyJob)
        .ContinueWith(task => Session.ScheduleTask(Session.Current.SessionId,
        (Session session, string sessionId) => {
            // might happen if this code is executed after the session has been destroyed
            if (session == null)
            {
                return;
            }
            try
            {
                // if LengthyJob resulted in exception, it will be unwrapped here
                this.Result = task.Result;
            }
            catch (Exception e)
            {
                this.Result = "Error";
            }
            finally
            {
                this.IsBusy = false;
                // otherwise the changes won't be immediately visible to the client
                session.CalculatePatchAndPushOnWebSocket();
            }
        }));
}

This library allows you to simplify this code by using async-await

public void Handle(Input.StartWorkTrigger input)
{
    AsyncInputHandlers.Run(async () =>
    {
        this.IsBusy = true;
        try
        {
            this.Result = await LengthyJob();
        }
        catch(Exception e)
        {
            this.Result = "Error";
        }
        finally
        {
            this.IsBusy = false;
        }
    });
}

Release Notes

Compatibility with 2.4, for 2.3-compatible version please use 1.0.0 of this package

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.0.0 369 3/19/2019