Scala - 多线程,当任何子线程完成时完成主线程

时间:2017-05-11 12:28:40

标签: multithreading scala

我正在构建一个方法,该方法采用x大小的方法序列并返回第一个方法的结果来完成。

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
  <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>

<body>
  <div data-role="page" id="page-list">
    <div data-theme="a" data-role="header" data-position="fixed">
      <h3>Users</h3>
    </div>
    <div data-role="content">
      <ul data-role="listview" data-inset="true" data-filter="true">
      </ul>
    </div>
  </div>
  <div data-role="page" id="page-card">
    <div data-theme="a" data-role="header" data-position="fixed">
      <h3>Details</h3>
      <a href="#" data-rel="back" class="ui-btn-left">Back</a>
    </div>
    <div data-role="content">
    </div>
  </div>
</body>

</html>

如何使用线程完成此操作? (不允许任何期货)

这是我能够提出的最好的,但似乎并不适用于所有情况。

def invokeAny(work: Seq[() => Int]): Int = ???

1 个答案:

答案 0 :(得分:0)

不是最温和的答案,但似乎有效:

<script>
var variable1 = conditions_for_variable_1;
var variable2 = conditions_for_variable_2;
var variable3 = conditions_for_variable_3;
var variable4 = conditions_for_variable_4;

if (variable1 && variable2 || variable3 || variable4) {window.open('website_A');}

else if (variable1 && variable2 && variable3 && variable4) {window.open('website_C');}

else if (variable1 ????? variable2 || variable3 || variable4) {window.open('website_D');}

else {window.open('website_E');}
</script>