Browse Source

Began making Wet Pancake lib. async.

master
Craig Oates 6 years ago
parent
commit
d354b07ad9
  1. 14
      WetPancake/ProductServices.fs
  2. 13
      WetPancakeCLI/ConsoleCommands.cs
  3. 1
      WetPancakeCLI/WetPancakeCLI.csproj

14
WetPancake/ProductServices.fs

@ -9,12 +9,14 @@ module Pancake =
open DataServices
let RequestRandomText() =
let data =
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups (PickRandomNumber 2 10)
|> GenerateMap
GenerateMarkovText (PickRandomNumber 2 10) data
async {
let data =
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups (PickRandomNumber 2 10)
|> GenerateMap
return GenerateMarkovText (PickRandomNumber 2 10) data
}
let RequestText (gibberishLevel: int) (sentences: int) =
let data =

13
WetPancakeCLI/ConsoleCommands.cs

@ -4,11 +4,20 @@ using System;
using static WetPancake.Pancake;
using static System.Environment;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.FSharp.Control;
using Microsoft.FSharp.Core;
using System.Threading;
namespace WetPancakeCLI
{
public static class ConsoleCommands
{
// Pass these in when running an FSharpAsync task.
// Examples are within the command-methods.
static FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None;
static FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None;
[ListCommand]
[Description("Prints a test message to the console.")]
[Parameters("None")]
@ -34,12 +43,12 @@ namespace WetPancakeCLI
public static string GenerateRandomText()
{
string result = String.Empty;
try { return RequestRandomText(); }
try { return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result; }
catch (Exception e)
{
Debug.WriteLine(e.Message);
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command...");
return RequestRandomText();
return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result;
}
}

1
WetPancakeCLI/WetPancakeCLI.csproj

@ -38,6 +38,7 @@
<Reference Include="Console.Waterworks, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Console.Waterworks.0.1.0.0-alpha1\lib\Console.Waterworks.dll</HintPath>
</Reference>
<Reference Include="FSharp.Core, Version=4.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">

Loading…
Cancel
Save