How to use BlockingCollection <'a> .TryTake in F #

How can I use the TryTake method in the BlockingCollection <'a> passing in the waiting period in milliseconds?

Here is the caption:

BlockingCollection.TryTake (item: byref, millisecondsTimeout: int): bool

Is it possible to use the Tuple method to avoid passing the ref type, for example, in Dictionary.TryGet methods?

those.
Let success, item = myDictionary.TryGetValue (client)

I am struggling with this particular signature, any suggestions would be great.

Hooray!

+3
source share
1 answer

, byref, ( ). , BlockingCollection.TryTake int * 'T byref -> bool, , 'T byref * int -> bool, .

:

open System.Runtime.InteropServices

type T =
  static member Meth1(a:int, [<Out>]b:string byref, [<Out>]c:bool byref) : char = 
    b <- sprintf "%i" a
    c <- a % 2 = 0
    char a
  static member Meth2([<Out>]b:string byref, [<Out>]c:bool byref, a:int) : char = 
    b <- sprintf "%i" a
    c <- a % 2 = 0
    char a

//  ok
let (r,b,c) = T.Meth1(5)
//  ok
let (r,c) = T.Meth1(5,ref "test")
// ok
let r = T.Meth1(5, ref "test", ref true)
// doesn't compile
let (r,b,c) = T.Meth2(5)
// doesn't compile
let (r,c) = T.Meth2(ref "test", 5)
// ok
let r = T.Meth2(ref "test", ref true, 5)
+3

Source: https://habr.com/ru/post/1790572/


All Articles