Skip to content

Commit 8bc06b6

Browse files
committed
add part-7
1 parent a9b07d9 commit 8bc06b6

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
62.8 KB
Binary file not shown.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<PropertyGroup>
5+
<!-- Enable the restore command to run before builds -->
6+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
7+
<PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
8+
<PaketRootPath>$(MSBuildThisFileDirectory)..\</PaketRootPath>
9+
<PaketLockFilePath>$(PaketRootPath)paket.lock</PaketLockFilePath>
10+
<PaketRestoreCacheFile>$(PaketRootPath)paket-files\paket.restore.cached</PaketRestoreCacheFile>
11+
<MonoPath Condition="'$(MonoPath)' == '' And Exists('/Library/Frameworks/Mono.framework/Commands/mono')">/Library/Frameworks/Mono.framework/Commands/mono</MonoPath>
12+
<MonoPath Condition="'$(MonoPath)' == ''">mono</MonoPath>
13+
</PropertyGroup>
14+
15+
<PropertyGroup>
16+
<!-- Paket command -->
17+
<PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketRootPath)paket.exe')">$(PaketRootPath)paket.exe</PaketExePath>
18+
<PaketExePath Condition=" '$(PaketExePath)' == '' ">$(PaketToolsPath)paket.exe</PaketExePath>
19+
<PaketCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
20+
<PaketCommand Condition=" '$(OS)' != 'Windows_NT' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)"</PaketCommand>
21+
</PropertyGroup>
22+
23+
<Choose> <!-- MyProject.fsproj.paket.references has the highest precedence -->
24+
<When Condition="Exists('$(MSBuildProjectFullPath).paket.references')">
25+
<PropertyGroup>
26+
<PaketReferences>$(MSBuildProjectFullPath).paket.references</PaketReferences>
27+
</PropertyGroup>
28+
</When> <!-- MyProject.paket.references -->
29+
<When Condition="Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references')">
30+
<PropertyGroup>
31+
<PaketReferences>$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references</PaketReferences>
32+
</PropertyGroup>
33+
</When> <!-- paket.references -->
34+
<When Condition="Exists('$(MSBuildProjectDirectory)\paket.references')">
35+
<PropertyGroup>
36+
<PaketReferences>$(MSBuildProjectDirectory)\paket.references</PaketReferences>
37+
</PropertyGroup>
38+
</When> <!-- Set to empty if a reference file isn't found matching one of the 3 format options -->
39+
<Otherwise>
40+
<PropertyGroup>
41+
<PaketReferences></PaketReferences>
42+
</PropertyGroup>
43+
</Otherwise>
44+
</Choose>
45+
46+
<PropertyGroup>
47+
<!-- Commands -->
48+
<RestoreCommand>$(PaketCommand) restore --references-file "$(PaketReferences)"</RestoreCommand>
49+
<!-- We need to ensure packages are restored prior to assembly resolve -->
50+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">RestorePackages; $(BuildDependsOn);</BuildDependsOn>
51+
</PropertyGroup>
52+
<Target Name="RestorePackages">
53+
<PropertyGroup>
54+
<PaketRestoreRequired>true</PaketRestoreRequired>
55+
</PropertyGroup>
56+
57+
<PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') ">
58+
<PaketRestoreCachedHash>$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash>
59+
<PaketRestoreLockFileHash>$([System.IO.File]::ReadAllText('$(PaketLockFilePath)'))</PaketRestoreLockFileHash>
60+
<PaketRestoreRequired>true</PaketRestoreRequired>
61+
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
62+
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired>
63+
</PropertyGroup>
64+
65+
<Exec Command="$(RestoreCommand)"
66+
IgnoreStandardErrorWarningFormat="true"
67+
WorkingDirectory="$(PaketRootPath)"
68+
ContinueOnError="false"
69+
Condition=" '$(PaketRestoreRequired)' == 'true' AND Exists('$(PaketReferences)') AND '$(PaketReferences)' != '' "
70+
/>
71+
</Target>
72+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source https://www.nuget.org/api/v2
2+
framework: net461
3+
nuget Hopac
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RESTRICTION: == net461
2+
NUGET
3+
remote: https://www.nuget.org/api/v2
4+
FSharp.Core (4.3.4)
5+
Hopac (0.3.23)
6+
FSharp.Core (>= 3.1.2.5)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#r "./packages/Hopac/lib/net45/Hopac.Core.dll"
2+
#r "./packages/Hopac/lib/net45/Hopac.Platform.dll"
3+
#r "./packages/Hopac/lib/net45/Hopac.dll"
4+
5+
open Hopac
6+
7+
type Image = Image of string
8+
type ImageJob = Image -> Job<Image>
9+
10+
let imageJob delay jobName (Image image) = job {
11+
printfn "%s Started: %s" jobName image
12+
do! timeOutMillis delay
13+
let newImage = sprintf "%s [%s]" image jobName
14+
printfn "%s Completed: %s" jobName newImage
15+
return (Image newImage)
16+
}
17+
18+
let scaleImage = imageJob 2000 "Scaling"
19+
let filterImage = imageJob 1500 "Filtering"
20+
let displayImage = imageJob 500 "Displaying"
21+
22+
type BoundedWorker (queueLength, f : ImageJob) =
23+
let inMb = new BoundedMb<Image>(queueLength)
24+
member __.CreateJob (count : int, outMb : BoundedMb<Image>) =
25+
BoundedMb.take inMb
26+
|> Alt.afterJob f
27+
|> Alt.afterJob (BoundedMb.put outMb)
28+
|> Job.forN count
29+
30+
member __.CreateJob (count : int) =
31+
BoundedMb.take inMb
32+
|> Alt.afterJob f
33+
|> Alt.afterFun (fun _ -> ())
34+
|> Job.forN count
35+
member __.InMb = inMb
36+
37+
38+
// Ch<'a> -> 'a list -> Alt<unit>
39+
let rec loadImages inMb inputs =
40+
match inputs with
41+
| [] -> Alt.always ()
42+
| x :: xs ->
43+
BoundedMb.put inMb x
44+
|> Alt.afterJob (fun _ -> loadImages inMb xs)
45+
46+
let pipeline images =
47+
let imagesCount = List.length images
48+
let queueLength = 3
49+
let imageScaler = BoundedWorker(queueLength, scaleImage)
50+
let imageFilterer = BoundedWorker(queueLength, filterImage)
51+
let imageDisplayer = BoundedWorker(queueLength, displayImage)
52+
53+
loadImages imageScaler.InMb images |> start
54+
[ imageScaler.CreateJob(imagesCount, imageFilterer.InMb)
55+
imageFilterer.CreateJob(imagesCount, imageDisplayer.InMb)
56+
imageDisplayer.CreateJob(imagesCount)]
57+
|> Job.conIgnore
58+
59+
60+
61+
let images = [Image "Foo.png"; Image "Bar.png";Image "Baz.png"]
62+
63+
#time "on"
64+
pipeline images |> run
65+
#time "off"
66+

0 commit comments

Comments
 (0)