質問

どのように人々は?Scalaで大小規模で継続を使用している

はCPSで書かれたScalaの標準ライブラリのどの部分?

継続を使用してのいずれかの主要なパフォーマンスの低下はありますか?

役に立ちましたか?

解決

私が代わりに書き込むのように、フォームdef func(...)(followup: Result => Unit): Unitの非同期機能をオンにするためにこれを使用しています。

foo(args){result1 => 
  bar(result1){result2 => 
     car(result2) {result3 =>
       //etc.
     }
  }
}

あなたが書くことができます。

val result1 = foo(args)
val result2 = bar(result1)
val result3 = car(result2)

または

car(bar(foo(args)))

(注:関数は一つの引数または引数として以前の結果を単に使用に限定されない)

http://www.tikalk.com/java/blog/asynchronous-を参照してください。機能-俳優-と-CPS

他のヒント

Scalaの-ARM の(自動-資源管理)用途区切られた継続

import java.io._
import util.continuations._
import resource._
def each_line_from(r : BufferedReader) : String @suspendable =
  shift { k =>
    var line = r.readLine
    while(line != null) {
      k(line)
      line = r.readLine
    }
  }
reset {
  val server = managed(new ServerSocket(8007)) !
  while(true) {
    // This reset is not needed, however the  below denotes a "flow" of execution that can be deferred.
    // One can envision an asynchronous execuction model that would support the exact same semantics as below.
    reset {
      val connection = managed(server.accept) !
      val output = managed(connection.getOutputStream) !
      val input = managed(connection.getInputStream) !
      val writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output)))
      val reader = new BufferedReader(new InputStreamReader(input))
      writer.println(each_line_from(reader))
      writer.flush()
    }
  }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top