swlaschin / Railway-Oriented-Programming-Example

This repository contains code that demonstrates the "Railway Oriented Programming" concept for error handling in functional programming languages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Asynchronous (controller) examples on "railways"

veikkoeeva opened this issue · comments

One uses asynchrouns methods quite often in ASP.NET MVC due to I/O bound operations such as calling backend services or a database. How should one handle an asynchronous call to a database, awaiting the result and then returning it? One would need to go asynchronous all the way, including the "railway" portion. For a very brief introduction, see Scaffolding asynchronous MVC and Web API controllers for Entity Framework 6 (latest is ASP.NET MVC 5.2). Also, many frameworks assume using Task/Task (does FSharpx implement TryWith in TaskBuilder?), which brings a slight wringle to the journey.

Also, I'd really like to see an example using Hopac, either alone or in conjunction with Task/async.

... And I really like these examples too. Really well constructed!

Thanks for this -- lots of people have asked for this, so I'll definitely do an update at some point.

That would be nice!

I'll take the liberty to add some directions to people that might pass by. Maybe there would also be a possibility to pool work? For instance, how to do a F# "WebApi" (CORS) that serves a "frontend"?

I'll add here there's an attempt to this direction at https://github.com/panesofglass/TodoBackendFSharp/blob/master/docs/index.md in "Dyfrig's OwinRailway".

That one has become a part of a wider discussion at Recommended F# approach for commercial Software as a Service application - also relates to "Sample Application" topic, Is F# not suited for generic web development? and this fine example at Lightweight websites with F#.

That's a good thread on google groups. I'll have to read it carefully!

Thanks for the links!

On 26 September 2014 21:55, Veikko Eeva notifications@github.com wrote:

That would be nice!

I'll take the liberty to add some directions to people that might pass by.
Maybe there would also be a possibility to pool resources here? For
instance, how to do a F# "WebApi" (CORS) that serves a "frontend"?

I'll add here there's an attempt to this direction at
https://github.com/panesofglass/TodoBackendFSharp/blob/master/docs/index.md
in "Dyfrig's OwinRailway".

That one has become a part of a wider discussion at Recommended F#
approach for commercial Software as a Service application - also relates to
"Sample Application" topic
https://groups.google.com/forum/#!topic/web-stack-fs/pn7PL9-Zo0g, Is F#
not suited for generic web development?
https://groups.google.com/forum/#!topic/fsharp-opensource/8hY8Z4RJzqA
and this fine example at Lightweight websites with F#
http://cockneycoder.wordpress.com/2014/09/03/lightweight-websites-with-f/
.


Reply to this email directly or view it on GitHub
#1 (comment)
.

Was there an async version of this ever implemented? Or a tutorial ever given on fsharpforfunandprofit? I'm having a hard time making the leap to async. Wish I was as smart as you guys! Getting there, very slowly :-)

The Chessie docs aren't very comprehensive so I didn't see anything helpful for async as in practical implementations.

I am interested in this as well. A railway pattern between async and non-async functions

@Swoorup ,

Using computation expressions is the way to go with these monads. It gets rather confusing if you don't. But there are plenty of examples and blog posts on the subject to make them more understandable. Below is a bunch of resources you can use to help you understand it all better!

Take a look at this tutorial series to understand computation expressions:

https://fsharpforfunandprofit.com/posts/elevated-world-5/

And then you can take a look at this AsyncChoiceBuilder:

https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Control.fs#L1478

And then you can take a look at my TaskResultBuilder:

https://github.com/jon49/Track/blob/behaviorjs/Server/src/Server/Libs/TaskResult.fs#L118

And that should get you there. There are more things I could have implemented, like having it work with with a straight Result value instead of having to lift it to a Task. But overall I was happy with my implementation.