Hi Richard,


On Tue, Feb 23, 2016 at 12:01 AM, Richard Rodseth <[email protected]>
wrote:

> I have some blocking code (a call to file.mkdirs()) that I am enclosing
> inside blocking {} as below.
>
> I have a feeling this may be incorrect. But I don't see a way to use
> ActorAttributes in this scenario.
>
>   // Is this the way to manage the blocking mkdirs?
>
>   import scala.concurrent.blocking
>
>   def mkdirs(file: File)(implicit ec: ExecutionContext): Future[(Boolean,
> Boolean)] = Future {
>
>     blocking {
>
>       val madeDirs = file.getParentFile.mkdirs()
>
>       val created = file.createNewFile()
>
>       (madeDirs, created)
>
>     }
>

Using above will mean that the FJP will launch compensating threads,
sometimes this can result in thread-blowup. I would rather recommend
dedicating a dispatcher for such blocking operations and passing it in as
the ExecutionContext.

And yes, ActorAttributes do not help here as this is a Future, not a stream.

-Endre


>   }
>
>   def writeFile(source: Source[ByteString, akka.NotUsed], file: File)(
> implicit ec: ExecutionContext, materializer: ActorMaterializer): Future[
> IOResult] = {
>
>     val result = for {
>
>       madeDirs <- mkdirs(file)
>
>       wroteBytes <- source/*.via(SnappyFlows.compress())*/.runWith(FileIO.
> toFile(file))
>
>     } yield wroteBytes
>
>     result
>
>   }
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to