Skip to content

Commit 39d14af

Browse files
committed
Remove IFDEFs
1 parent 82ed47c commit 39d14af

9 files changed

Lines changed: 16 additions & 141 deletions

File tree

FSharpx.Async.sln

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
2+
# Visual Studio 2013
3+
VisualStudioVersion = 12.0.31101.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
45
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{63297B98-5CED-492C-A5B7-A5B4F73CF142}"
5-
ProjectSection(SolutionItems) = preProject
6+
ProjectSection(SolutionItems) = preProject
67
paket.dependencies = paket.dependencies
78
paket.lock = paket.lock
89
EndProjectSection
910
EndProject
10-
EndProject
1111
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{A6A6AF7D-D6E3-442D-9B1E-58CC91879BE1}"
1212
EndProject
1313
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpx.Async", "src\FSharpx.Async\FSharpx.Async.fsproj", "{2D4F3D0E-0E18-48D7-9C27-98864039393D}"
@@ -29,7 +29,6 @@ EndProject
2929
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D5255-776D-4B61-85F9-73C37AA1FB9A}"
3030
ProjectSection(SolutionItems) = preProject
3131
docs\content\index.fsx = docs\content\index.fsx
32-
docs\content\tutorial.fsx = docs\content\tutorial.fsx
3332
EndProjectSection
3433
EndProject
3534
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{ED8079DD-2B06-4030-9F0F-DC548F98E1C4}"

src/FSharpx.Async/Async.IO.fs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ module IOExtensions =
3131
do! x.AsyncWrite(data) }
3232

3333
open System
34-
#if NET40
35-
open System.Diagnostics.Contracts
36-
#else
3734
open System.Diagnostics
38-
#endif
35+
open System.Diagnostics.Contracts
3936

4037
// Loosely based on Stephen Toub's Stream Pipelines article in MSDN.
4138
// See http://msdn.microsoft.com/en-us/magazine/cc163290.aspx
@@ -59,45 +56,27 @@ type CircularStream(maxLength) =
5956
override x.SetLength(value) = raise <| new NotSupportedException()
6057

6158
override x.Read(buffer, offset, count) =
62-
#if NET40
6359
Contract.Requires(buffer <> null, "buffer cannot be null")
6460
Contract.Requires(offset >= 0 && offset < buffer.Length, "offset is out of range")
6561
Contract.Requires(count >= 0 && offset + count <= buffer.Length, "count is out of range")
66-
#else
67-
Debug.Assert(buffer <> null, "buffer cannot be null")
68-
Debug.Assert(offset >= 0 && offset < buffer.Length, "offset is out of range")
69-
Debug.Assert(count >= 0 && offset + count <= buffer.Length, "count is out of range")
70-
#endif
7162

7263
if count = 0 then 0 else
7364
let chunk = queue.Dequeue(count)
7465
Buffer.BlockCopy(chunk, 0, buffer, offset, chunk.Length)
7566
chunk.Length
7667

7768
override x.Write(buffer, offset, count) =
78-
#if NET40
7969
Contract.Requires(buffer <> null, "buffer cannot be null")
8070
Contract.Requires(offset >= 0 && offset < buffer.Length, "offset is out of range")
8171
Contract.Requires(count >= 0 && offset + count <= buffer.Length, "count is out of range")
82-
#else
83-
Debug.Assert(buffer <> null, "buffer cannot be null")
84-
Debug.Assert(offset >= 0 && offset < buffer.Length, "offset is out of range")
85-
Debug.Assert(count >= 0 && offset + count <= buffer.Length, "count is out of range")
86-
#endif
8772

8873
if count = 0 then () else
8974
queue.Enqueue(buffer, offset, count)
9075

9176
member x.AsyncRead(buffer: byte[], offset, count, ?timeout) =
92-
#if NET40
9377
Contract.Requires(buffer <> null, "buffer cannot be null")
9478
Contract.Requires(offset >= 0 && offset < buffer.Length, "offset is out of range")
9579
Contract.Requires(count >= 0 && offset + count <= buffer.Length, "count is out of range")
96-
#else
97-
Debug.Assert(buffer <> null, "buffer cannot be null")
98-
Debug.Assert(offset >= 0 && offset < buffer.Length, "offset is out of range")
99-
Debug.Assert(count >= 0 && offset + count <= buffer.Length, "count is out of range")
100-
#endif
10180

10281
if count = 0 then async.Return(0) else
10382
async {
@@ -106,19 +85,13 @@ type CircularStream(maxLength) =
10685
return chunk.Length }
10786

10887
member x.AsyncWrite(buffer: byte[], offset, count, ?timeout) =
109-
#if NET40
11088
Contract.Requires(buffer <> null, "buffer cannot be null")
11189
Contract.Requires(offset >= 0 && offset < buffer.Length, "offset is out of range")
11290
Contract.Requires(count >= 0 && offset + count <= buffer.Length, "count is out of range")
113-
#else
114-
Debug.Assert(buffer <> null, "buffer cannot be null")
115-
Debug.Assert(offset >= 0 && offset < buffer.Length, "offset is out of range")
116-
Debug.Assert(count >= 0 && offset + count <= buffer.Length, "count is out of range")
117-
#endif
11891

11992
if count = 0 then async.Zero() else
12093
async { do! queue.AsyncEnqueue(buffer, offset, count, ?timeout = timeout) }
12194

12295
override x.Close() =
12396
base.Close()
124-
// TODO: Close the queue agent.
97+
// TODO: Close the queue agent.

src/FSharpx.Async/Async.fs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,4 @@ module AsyncExtensions =
3434
let ct = new System.Threading.CancellationTokenSource()
3535
Async.Start(op, ct.Token)
3636
{ new IDisposable with
37-
member x.Dispose() = ct.Cancel() }
38-
39-
#if NET40
40-
41-
/// Starts a non-generic Task with the cancellationToken and returns an
42-
/// Async<unit> containing the result.
43-
static member AwaitTask(task:Tasks.Task, ?cancellationToken) =
44-
let cancel = defaultArg cancellationToken Async.DefaultCancellationToken
45-
Async.AwaitTask <| task.ContinueWith<unit>((fun t -> ()), cancel)
46-
47-
/// Starts a Task<'a> with the timeout and cancellationToken and
48-
/// returns a Async<a' option> containing the result. If the Task does
49-
/// not complete in the timeout interval, or is faulted None is returned.
50-
static member TryAwaitTask(task:Tasks.Task<_>, ?timeout, ?cancellationToken) =
51-
let timeout = defaultArg timeout Timeout.Infinite
52-
let cancel = defaultArg cancellationToken Async.DefaultCancellationToken
53-
async {
54-
return
55-
if task.Wait(timeout, cancel) && not task.IsCanceled && not task.IsFaulted
56-
then Some task.Result
57-
else None }
58-
59-
/// Implements an extension method that overloads the standard
60-
/// 'Bind' of the 'async' builder. The new overload awaits on
61-
/// a standard .NET task
62-
type Microsoft.FSharp.Control.AsyncBuilder with
63-
member x.Bind(t:Tasks.Task<'T>, f:'T -> Async<'R>) : Async<'R> = async.Bind(Async.AwaitTask t, f)
64-
member x.Bind(t:Tasks.Task, f:unit -> Async<'R>) : Async<'R> = async.Bind(Async.AwaitTask t, f)
65-
66-
#endif
37+
member x.Dispose() = ct.Cancel() }

src/FSharpx.Async/AsyncOperations.fs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,11 @@ namespace FSharpx.Control
5151
| [] -> ()
5252
| [cont] when reuseThread -> cont res
5353
| otherwise ->
54-
#if FX_NO_SYNC_CONTEXT
55-
let postOrQueue cont = ThreadPool.QueueUserWorkItem(fun _ -> cont res) |> ignore
56-
#else
5754
let synchContext = System.Threading.SynchronizationContext.Current
5855
let postOrQueue =
5956
match synchContext with
6057
| null -> fun cont -> ThreadPool.QueueUserWorkItem(fun _ -> cont res) |> ignore
61-
| sc -> fun cont -> sc.Post((fun _ -> cont res), state=null)
62-
#endif
58+
| sc -> fun cont -> sc.Post((fun _ -> cont res), state=null)
6359
grabbedConts |> List.iter postOrQueue
6460

6561
/// Get the reified result
@@ -108,39 +104,20 @@ namespace FSharpx.Control
108104
static member AsyncAppendText(path) = UnblockViaNewThread (fun () -> System.IO.File.AppendText(path))
109105
static member AsyncOpenRead(path) = UnblockViaNewThread (fun () -> System.IO.File.OpenRead(path))
110106
static member AsyncOpenWrite(path) = UnblockViaNewThread (fun () -> System.IO.File.OpenWrite(path))
111-
#if FX_NO_FILE_OPTIONS
112-
static member AsyncOpen(path,mode,?access,?share,?bufferSize) =
113-
#else
114107
static member AsyncOpen(path,mode,?access,?share,?bufferSize,?options) =
115-
#endif
116108
let access = match access with Some v -> v | None -> System.IO.FileAccess.ReadWrite
117109
let share = match share with Some v -> v | None -> System.IO.FileShare.None
118-
#if FX_NO_FILE_OPTIONS
119-
#else
120110
let options = match options with Some v -> v | None -> System.IO.FileOptions.None
121-
#endif
122111
let bufferSize = match bufferSize with Some v -> v | None -> 0x1000
123112
UnblockViaNewThread (fun () ->
124-
#if FX_NO_FILE_OPTIONS
125-
new System.IO.FileStream(path,mode,access,share,bufferSize))
126-
#else
127113
new System.IO.FileStream(path,mode,access,share,bufferSize, options))
128-
#endif
129114

130115
static member OpenTextAsync(path) = System.IO.File.AsyncOpenText(path)
131116
static member AppendTextAsync(path) = System.IO.File.AsyncAppendText(path)
132117
static member OpenReadAsync(path) = System.IO.File.AsyncOpenRead(path)
133118
static member OpenWriteAsync(path) = System.IO.File.AsyncOpenWrite(path)
134-
#if FX_NO_FILE_OPTIONS
135-
static member OpenAsync(path,mode,?access,?share,?bufferSize) =
136-
System.IO.File.AsyncOpen(path, mode, ?access=access, ?share=share,?bufferSize=bufferSize)
137-
#else
138119
static member OpenAsync(path,mode,?access,?share,?bufferSize,?options) =
139120
System.IO.File.AsyncOpen(path, mode, ?access=access, ?share=share,?bufferSize=bufferSize,?options=options)
140-
#endif
141-
142-
#if FX_NO_FILE_OPTIONS
143-
#else
144121

145122
// Aims to take advantage of IO completion ports using FileStream.AsyncWrite and FileOptions.Asynchronous, so no FX_NO_FILE_OPTIONS version
146123
static member AsyncWriteAllBytes(path, bytes) =
@@ -196,12 +173,6 @@ namespace FSharpx.Control
196173

197174

198175

199-
#endif
200-
201-
202-
203-
204-
205176

206177

207178
[<AutoOpen>]
@@ -211,8 +182,6 @@ namespace FSharpx.Control
211182
member s.AsyncReadToEnd () = FileExtensions.UnblockViaNewThread (fun () -> s.ReadToEnd())
212183
member s.ReadToEndAsync () = s.AsyncReadToEnd ()
213184

214-
#if FX_NO_WEB_REQUESTS
215-
#else
216185
[<AutoOpen>]
217186
module WebRequestExtensions =
218187
open System
@@ -224,10 +193,7 @@ namespace FSharpx.Control
224193
type System.Net.WebRequest with
225194
member req.AsyncGetResponse() = callFSharpCoreAsyncGetResponse req // this calls the FSharp.Core method
226195
member req.GetResponseAsync() = callFSharpCoreAsyncGetResponse req // this calls the FSharp.Core method
227-
#endif
228196

229-
#if FX_NO_WEB_CLIENT
230-
#else
231197
[<AutoOpen>]
232198
module WebClientExtensions =
233199
open System.Net
@@ -319,5 +285,3 @@ namespace FSharpx.Control
319285
this.buildAsyncAction(
320286
this.DownloadDataCompleted,
321287
(fun token -> this.DownloadDataAsync(address, token)))
322-
#endif
323-

src/FSharpx.Async/AsyncOperations.fsi

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ namespace FSharpx.Control
5858
/// Create an async that opens a <c>System.IO.FileStream</c> on the specified path, via a fresh I/O thread.
5959
/// Pass <c>options=FileOptions.Asynchronous</c> to enable further asynchronous read/write operations
6060
/// on the FileStream.
61-
#if FX_NO_FILE_OPTIONS
62-
static member AsyncOpen: path:string * mode:FileMode * ?access: FileAccess * ?share: FileShare * ?bufferSize: int -> Async<FileStream>
63-
#else
6461
static member AsyncOpen: path:string * mode:FileMode * ?access: FileAccess * ?share: FileShare * ?bufferSize: int * ?options: FileOptions -> Async<FileStream>
6562

6663
// Aims to take advantage of IO completion ports using FileStream.AsyncWrite and FileOptions.Asynchronous, so no FX_NO_FILE_OPTIONS version
@@ -71,20 +68,13 @@ namespace FSharpx.Control
7168
static member AsyncAppendAllText: path:string * txt:string * ?encoder:System.Text.Encoding -> Async<unit>
7269
static member AsyncAppendAllLines: path:string * lines:string array * ?encoder:System.Text.Encoding -> Async<unit>
7370

74-
#endif
75-
76-
#if FX_NO_WEB_REQUESTS
77-
#else
7871
[<AutoOpen>]
7972
module WebRequestExtensions =
8073
type System.Net.WebRequest with
8174
/// Return an asynchronous computation that, when run, will wait for a response to the given WebRequest.
8275
[<System.Obsolete("The extension method now resides in the 'WebExtensions' module in the F# core library. Please add 'open Microsoft.FSharp.Control.WebExtensions' to access this method")>]
8376
member AsyncGetResponse : unit -> Async<System.Net.WebResponse>
84-
#endif
85-
86-
#if FX_NO_WEB_CLIENT
87-
#else
77+
8878
[<AutoOpen>]
8979
module WebClientExtensions =
9080
type System.Net.WebClient with
@@ -121,5 +111,4 @@ namespace FSharpx.Control
121111
member AsyncDownloadFile : address: System.Uri * fileName: string -> Async<unit>
122112

123113
/// Returns an asynchronous computation that, when run, will wait for the download of the specified resource as a data buffer.
124-
member AsyncDownloadData : address: System.Uri -> Async<byte[]>
125-
#endif
114+
member AsyncDownloadData : address: System.Uri -> Async<byte[]>

src/FSharpx.Async/AsyncStreamReader.fs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ type AsyncStreamReader(stream:Stream, encoding:Encoding, detectEncodingFromByteO
3434

3535
if not stream.CanRead then
3636
invalidArg "stream" "stream not readable";
37-
#if FX_NO_FILESTREAM_ISASYNC
38-
#else
37+
3938
match stream with
4039
| :? System.IO.FileStream as fs when not fs.IsAsync ->
4140
invalidArg "stream" "FileStream not asynchronous. AsyncStreamReader should only be used on FileStream if the IsAsync property returns true. Consider passing 'true' for the async flag in the FileStream constructor"
4241
| _ ->
4342
()
44-
#endif
43+
4544
if (bufferSize <= 0) then
4645
raise <| new ArgumentOutOfRangeException("bufferSize");
4746

@@ -125,8 +124,7 @@ type AsyncStreamReader(stream:Stream, encoding:Encoding, detectEncodingFromByteO
125124
encoding <- new UnicodeEncoding(true, true);
126125
compressBuffer(2);
127126
changedEncoding <- true;
128-
#if FX_NO_UTF32ENCODING
129-
#else
127+
130128
elif (byteBuffer.[0]=0xFFuy && byteBuffer.[1]=0xFEuy) then
131129
// Little Endian Unicode, or possibly little endian UTF32
132130
if (byteLen >= 4 && byteBuffer.[2] = 0uy && byteBuffer.[3] = 0uy) then
@@ -136,19 +134,17 @@ type AsyncStreamReader(stream:Stream, encoding:Encoding, detectEncodingFromByteO
136134
encoding <- new UnicodeEncoding(false, true);
137135
compressBuffer(2);
138136
changedEncoding <- true;
139-
#endif
140137
elif (byteLen >= 3 && byteBuffer.[0]=0xEFuy && byteBuffer.[1]=0xBBuy && byteBuffer.[2]=0xBFuy) then
141138
// UTF-8
142139
encoding <- Encoding.UTF8;
143140
compressBuffer(3);
144141
changedEncoding <- true;
145-
#if FX_NO_UTF32ENCODING
146-
#else
142+
147143
elif (byteLen >= 4 && byteBuffer.[0] = 0uy && byteBuffer.[1] = 0uy && byteBuffer.[2] = 0xFEuy && byteBuffer.[3] = 0xFFuy) then
148144
// Big Endian UTF32
149145
encoding <- new UTF32Encoding(true, true);
150146
changedEncoding <- true;
151-
#endif
147+
152148
elif (byteLen = 2) then
153149
_detectEncoding <- true;
154150
// Note: in the future, if we change this algorithm significantly,

src/FSharpx.Async/AsyncWorker.fs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace FSharpx.Control
1010
open Microsoft.FSharp.Control
1111
open Microsoft.FSharp.Collections
1212

13-
#if FX_NO_SYNC_CONTEXT
14-
#else
1513
type AsyncWorker<'T>(p : Async<'T>,?cancellationToken) =
1614

1715
let cts =
@@ -63,6 +61,3 @@ namespace FSharpx.Control
6361
member x.Completed = completed.Publish
6462
member x.Canceled = canceled.Publish
6563
member x.Error = error.Publish
66-
67-
68-
#endif

src/FSharpx.Async/AsyncWorker.fsi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace FSharpx.Control
88
open System.Threading
99
open Microsoft.FSharp.Control
1010

11-
#if FX_NO_SYNC_CONTEXT
12-
#else
1311
type AsyncWorker<'T> =
1412
new : Async<'T> * ?asyncGroup: CancellationToken -> AsyncWorker<'T>
1513
member ProgressChanged : IEvent<int>
@@ -18,6 +16,4 @@ namespace FSharpx.Control
1816
member Canceled : IEvent<OperationCanceledException>
1917
member RunAsync : unit -> bool
2018
member ReportProgress : int -> unit
21-
member CancelAsync : ?message:string -> unit
22-
23-
#endif
19+
member CancelAsync : ?message:string -> unit

src/FSharpx.Async/Observable.fs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,7 @@ module Observable =
280280
async {
281281
let! cToken = Async.CancellationToken
282282
let token : CancellationToken = cToken
283-
#if NET40
284-
use registration = token.Register(fun () -> remove())
285-
#else
286283
use registration = token.Register((fun _ -> remove()), null)
287-
#endif
288284
return! workflow
289285
})
290286

@@ -320,11 +316,7 @@ module Observable =
320316
async {
321317
let! cToken = Async.CancellationToken
322318
let token : CancellationToken = cToken
323-
#if NET40
324-
use registration = token.Register(fun () -> remove())
325-
#else
326319
use registration = token.Register((fun _ -> remove()), null)
327-
#endif
328320
return! workflow
329321
})
330322

0 commit comments

Comments
 (0)