scala - Are Iteratees safe for managing resources? -


Suppose I was reading from InputStream .

How do I generally do this:

  val inputStream = ... try {doStuff (inputStream)} {end_stream.close ()}  

Whether or not DoStuff throws an exception, we will close InputStream .


How do I do this with an internet address:

  wal inputstream ... anamorater.fromstream (inputstream) (iteratee foreac (dustf))  

Will InputStream be closed (even if doStuff throws an exception?)

A small test: < / P>

  val inputStream = new InputStream () {// 10, 9, ... 0 returns, 1 private var i = 10 def () = {i = math.max (0, i) - 1 i} Override def close () = println ("closed") // Looking for this} Animator.fromstream (inputstream) (Iteratee.foreach (a = & gt; 1/0)) Only full println  

view only:

  failure (java.lang.ArithmeticException: / by zero)  

The stream was never switched on 1/0 with 1/1 and you will see that the stream is closed.

Of course, I can maintain the context of the original. In case of failure, turn it off and close it, but the idea of ​​using AAIAIAT to use the etarites is creating constructive repetition without doing this. is.


  1. Is this the expected behavior?

  2. Is the resources used properly?

  3. Post-text "itemprop =" text ">

    The content was designed specifically for secure resource management. first See the sentence:

    Iteratee IO is a style of incremental input processing with precise resource control.

    The idea is that when your resource is only used for iteratease If access is done through the medium, then the resource-owner code can actually tell that with the resource When it has begun, and close it immediately On the other hand, when the repetition is managed manually (such as with traditional InputStream ) the user of the resource is responsible for closing it.

    By saying this, there was a bug in Play 2.1 where fromStream did not manage the closing of its underlying InputStream ! This bug play 2.2

    You can see to see that Anmeretr How to stop the resource using onDoneEnumerating has expired has been fixed.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -