f# - Does using the same instance of a builder class concurrently cause any side effects? -
i want use computation expressions inside implementation of f# class intended c# consumption. interop class singleton (one instance wired in container) , used across threads (web requests).
the builder consists of methods , has no backing fields or state.
given following customary in f#:
module = let private build = new somebuilder()
does mean multiple expressions associated 1 builder can evaluated concurrently no problems?
under hood, builder doesn't "work" @ all. compiler converts computation expression series of method calls on builder, , compiles that.
therefore, thread-safety of builder wholly dependent on thread-safety of methods - i.e. methods write.
for example, following code:
mybuilder { let! x = f() let! y = g(x) return x + y }
would converted following:
mybuilder.bind( f(), fun x -> mybuilder.bind( g(x), fun y -> mybuilder.return( x + y ) ) )
(note: above code may not exact, conveys gist)
Comments
Post a Comment