Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for async code in C1 functions #789

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Conversation

napernik
Copy link
Contributor

No description provided.

@burningice2866
Copy link
Contributor

Can you explain a bit more in detail how this is suppose to work? As far as i can see, the only concrete thing added here is a InitializeAsync method to Razor functions that wants to be async. How is this method going to be used and how does it solve razor function doing async calls while executing its body?

@burningice2866
Copy link
Contributor

burningice2866 commented Nov 19, 2021

From what i can see, there are some heavy assumptions that Async != webforms.

Lets not forget that webforms is perfectly capable of running async, so one could find it plausible to add the IAsyncPageRenderer interface to the Masterpage template renderer, but that would break everything since you have hardcoded the assumption that if we have a async page renderer, then it can't be webforms.

@napernik
Copy link
Contributor Author

@burningice2866

How is this method going to be used and how does it solve razor function doing async calls while executing its body?

The way it would work for a razor function -> InitializeAzync will be called after the parameters are initialized and before the cshtml main body code is executed.
This way a Razor function can call async APIs and load the necessary data, save it a class field, and then the main body can synchronously render the response.

@inherits AsyncRazorFunction
@using System.Threading.Tasks
@using Orckestra.Composer.Search.Context;
@using Orckestra.Composer.Search.ViewModels

@functions {
    public override string FunctionDescription { get { return "Category Browsing Selected Facets"; }  }

    public IBrowseCategoryRequestContext BrowsingRequestContext { get; set; }

    public override async Task InitializeAsync()
    {
        _categoryBrowsingViewModel = await BrowsingRequestContext.GetViewModelAsync();
    }

    private CategoryBrowsingViewModel _categoryBrowsingViewModel;
}

@{
    if (_categoryBrowsingViewModel == null)  { return; }
     ...
}

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
<head>
</head>
<body>
    .....
</body>
</html>

@napernik
Copy link
Contributor Author

@burningice2866

From what i can see, there are some heavy assumptions that Async != webforms.

Lets not forget that webforms is perfectly capable of running async, so one could find it plausible to add the IAsyncPageRenderer interface to the Masterpage template renderer, but that would break everything since you have hardcoded the assumption that if we have a async page renderer, then it can't be webforms.

Currently, we don't aim for Web Forms + async support, as with eventual switch to .NET Core, we'll have to discontinue Web Forms support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants