Skip to content

Instantly share code, notes, and snippets.

@khalidabuhakmeh
Created March 4, 2014 19:49
Show Gist options
  • Select an option

  • Save khalidabuhakmeh/9354178 to your computer and use it in GitHub Desktop.

Select an option

Save khalidabuhakmeh/9354178 to your computer and use it in GitHub Desktop.
public ActionResult Index() {
return ProgressFlushResult(x => {
x.PartialView("First");
x.PartialView("Second");
x.PartialView("Third");
});
}
@nikmd23
Copy link

nikmd23 commented Mar 4, 2014

You've already done all the "work" (DB queries or service calls) by the time you hit return.

I'm thinking of moving towards:

[FlushEarly("Head")] // This could be a controller or global level filter
public ActionResult Index() {
    // do work

    return PartialView("Remainder");
});

The [FlushEarly("Head")] would run before the first line of code in the action result.

Of course, the Flush(ActionResult) method I proposed in my blog would still be required when you were using a dynamic head.

@nikmd23
Copy link

nikmd23 commented Mar 4, 2014

But for my money, yield return is still the most elegant way to do this.

@khalidabuhakmeh
Copy link
Author

You essentially want to create a "Workflow", which at the end of each state/node you want to flush. The yield return might be confusing to devs who might be familiar with that construct as it pertains to an "enumerable" thing.

I personally would prefer a more explicit implementation to something like this so it sticks out.

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