Skip to content

Commit f049fb2

Browse files
authored
Merge pull request #5 from TheAngryByrd/disposable-stack
Disposable stack
2 parents 4dd94a0 + e21cc3b commit f049fb2

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ dist: xenial
44

55
dotnet: 2.1.401
66
mono:
7-
- 5.14.0
87
- latest # => "stable release"
98
- alpha
109
- beta
@@ -23,7 +22,6 @@ script:
2322
matrix:
2423
fast_finish: true
2524
allow_failures:
26-
- mono: latest
2725
- mono: alpha
2826
- mono: beta
2927
- mono: weekly

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"tab.unfocusedActiveBorder": "#fff0"
4+
}
5+
}

src/FsLibLog/FsLibLog.fs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,23 @@ module Types =
4747

4848
[<AutoOpen>]
4949
module Inner =
50-
type DisposableList (disposables : IDisposable list) =
50+
open System.Collections.Generic
51+
52+
type DisposableStack() =
53+
let stack = Stack<IDisposable>()
54+
5155
interface IDisposable with
5256
member __.Dispose () =
53-
disposables |> List.iter(fun d -> try d.Dispose() with e -> printfn "%A" e)
57+
while stack.Count > 0 do
58+
stack.Pop().Dispose()
59+
60+
member __.Push (item : IDisposable) = stack.Push item
61+
member __.Push (items : IDisposable list) = items |> List.iter stack.Push
5462

55-
static member Create (disposables : IDisposable list) = new DisposableList(disposables)
63+
static member Create (items : IDisposable list) =
64+
let ds = new DisposableStack()
65+
ds.Push items
66+
ds
5667

5768
type ILog with
5869

@@ -69,8 +80,8 @@ module Types =
6980
use __ =
7081
log.AdditionalNamedParameters
7182
|> List.map(fun (key,value, destructure) -> logger.MappedContext key value destructure)
72-
|> List.rev // This reverse is important, it causes us to unwind as if you have multiple uses in a row
73-
|> DisposableList.Create
83+
// This stack is important, it causes us to unwind as if you have multiple uses in a row
84+
|> DisposableStack.Create
7485

7586
log.Parameters
7687
|> List.toArray

0 commit comments

Comments
 (0)