Skip to content

Commit

Permalink
added ClientPool<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Dec 16, 2022
1 parent e89133c commit 49643e1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/NBomber/Api/Shared.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
namespace NBomber

open System
open System.Collections.Generic
open System.Runtime.CompilerServices
open NBomber.Contracts
open NBomber.Extensions.Internal

type ClientPool<'T>() as this =

let mutable _disposed = false
let _clients = ResizeArray<'T>()

member _.Clients = _clients :> IReadOnlyList<_>
member _.AddClient(client) = _clients.Add client

member _.GetClient(scenarioInfo: ScenarioInfo) =
let index = scenarioInfo.ThreadNumber % _clients.Count
_clients[index]

member _.DisposeClients() =
if not _disposed then
_disposed <- true

for c in _clients do
match box c with
| :? IDisposable as client -> client.Dispose()
| _ -> ()

member _.DisposeClients(disposeClient: Action<'T>) =
if not _disposed then
_disposed <- true

for c in _clients do
disposeClient.Invoke c

interface IDisposable with
member _.Dispose() =
this.DisposeClients()

module Converter =

[<CompiledName("FromMicroSecToMs")>]
Expand Down

0 comments on commit 49643e1

Please sign in to comment.