2

有人有一个 fork/join 的工作示例,因为我收到了 芭蕾舞女演员: 每次我尝试用它做某事时都会发生意外错误。

谢谢,

胡安·巴勃罗

4

1 回答 1

3

以下是一个工作分叉连接示例。请尝试使用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

请张贴您的代码让我们看看有什么问题。

于 2017-03-06T16:32:09.830 回答