Asynchronous IO in Scala with futures

前端 未结 3 1690
广开言路
广开言路 2020-11-28 01:17

Let\'s say I\'m getting a (potentially big) list of images to download from some URLs. I\'m using Scala, so what I would do is :

import scala.actors.Futures.         


        
3条回答
  •  执念已碎
    2020-11-28 01:59

    1. Yes, seems fine to me, but you may want to investigate more powerful twitter-util or Akka Future APIs (Scala 2.10 will have a new Future library in this style).

    2. It uses a thread pool.

    3. No, it won't. You need to use the standard mechanism of your GUI toolkit for this (SwingUtilities.invokeLater for Swing or Display.asyncExec for SWT). E.g.

      fimages.foreach (_.foreach(im => SwingUtilities.invokeLater(new Runnable { display im })))
      

提交回复
热议问题