2017-03-06 45 views

回答

3

以下是一個工作的fork-join樣品。請嘗試使用ballerina run main forkjoin.bal。您可以用您的文件名替換forkjoin.bal。

import ballerina.lang.system; 
import ballerina.lang.messages; 

function main(string[] args) { 
    message m = {}; 
    testForkJoinAll(m); 
} 

function testForkJoinAll(message m)(message[]) { 

    message[] results; 
    json error; 
    system:println("Airfare "); 

    fork (m) { 
     worker ABC_Airline (message m) { 
      json payload; 
      payload = `{"name":"abc"}`; 
      messages:setJsonPayload(m, payload); 
      reply m; 
     } 

     worker XYZ_Airline (message m) { 
      json payload; 
      payload = `{"name":"xyz"}`; 
      messages:setJsonPayload(m, payload); 
      reply m; 
     } 
    } join (all) (message[] airlineResponses) { 
     system:println(messages:getStringPayload(airlineResponses[0])); 
     system:println(messages:getStringPayload(airlineResponses[1])); 
     return airlineResponses; 
    } timeout (30000) (message[] airlineResponses) { 
     system:println("error occurred"); 
     error = `{"error":{"code":"500", "reason":"timed out"}}`; 
     message res = {}; 
     messages:setJsonPayload(res, error); 
     results[0] = m; 
     return results; 
    } 
} 

以上是上述代碼的來源。 https://github.com/ballerinalang/ballerina/blob/007127a62c20e69eb9707c19cd82fbec8056a04a/modules/ballerina-native/src/test/resources/samples/fork-join-in-function.bal#L6-L6

請張貼你的代碼給我們看看最新的錯誤。

+0

它的工作原理。謝謝Sameera。 –

+0

我明白爲什麼我有這個問題。我不會把「超時」部分,你收到芭蕾舞演員:發生意外的錯誤。 –

+0

好:)你可以請在這裏創建一個問題https://github.com/ballerinalang/ballerina/issues?我們將改進錯誤信息。 –