Skip to content

Commit

Permalink
Use cancellation token default value instead of option
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Nov 28, 2023
1 parent 4a1add2 commit d7ce3bd
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/Compiler/Utilities/Cancellable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@ open System.Threading
[<Sealed>]
type Cancellable =
[<ThreadStatic; DefaultValue>]
static val mutable private token: CancellationToken option
static val mutable private token: CancellationToken

static member UsingToken(ct) =
let oldCt = Cancellable.token

Cancellable.token <- Some ct
Cancellable.token <- ct

{ new IDisposable with
member this.Dispose() = Cancellable.token <- oldCt
}

static member Token
with get () =
match Cancellable.token with
| None -> CancellationToken.None
| Some ct -> ct
and internal set v = Cancellable.token <- Some v
with get () = Cancellable.token
and internal set v = Cancellable.token <- v

static member CheckAndThrow() =
match Cancellable.token with
| Some token -> token.ThrowIfCancellationRequested()
| _ -> ()
Cancellable.token.ThrowIfCancellationRequested()

namespace Internal.Utilities.Library

Expand Down

0 comments on commit d7ce3bd

Please sign in to comment.