1717import ballerina /jballerina .java ;
1818import ballerina /time ;
1919
20+ # Record type for activity parameters.
21+ # Used to pass arguments to activity functions in a type-safe manner.
22+ public type Parameters record {|
23+ anydata ... ;
24+ | };
25+
2026# Workflow execution context providing workflow APIs.
2127# This is a client object that provides access to workflow operations.
2228#
2329# This client provides:
24- # - Activity execution via `callActivity() ` remote method
30+ # - Activity execution via `callActivity` remote method
2531# - Durable sleep operations
2632# - Workflow state queries (replaying status, workflow ID, workflow type)
2733#
28- # Use `check ctx. callActivity(myActivity, arg1, arg2)` to execute activities.
34+ # Use `check ctx-> callActivity(myActivity, {" arg1": val1, " arg2": val2} )` to execute activities.
2935# Use Ballerina's `wait` action with event futures for signal handling.
3036public client class Context {
3137 private handle nativeContext ;
@@ -43,17 +49,24 @@ public client class Context {
4349 # that should only be executed once during workflow execution and not during replay.
4450 # The workflow runtime ensures exactly-once execution semantics for activities.
4551 #
52+ # The return type is determined by the `T` typedesc parameter, allowing compile-time
53+ # type checking when the expected return type is specified. The compiler plugin
54+ # validates that the activity function's return type is compatible with `T`.
55+ #
4656 # Example:
4757 # ```ballerina
48- # string result = check ctx. callActivity(sendEmailActivity, recipientEmail, subject);
58+ # string result = check ctx-> callActivity(sendEmailActivity, {"email": recipientEmail, " subject": subject} );
4959 # ```
5060 #
5161 # + activityFunction - The activity function to execute (must be annotated with @Activity)
52- # + args - Variable arguments to pass to the activity function
53- # + return - The result of the activity execution, or an error if execution fails
54- remote isolated function callActivity(function activityFunction , anydata ... args ) returns anydata | error {
55- return callActivityNative (self .nativeContext , activityFunction , ...args );
56- }
62+ # + args - Record containing the arguments to pass to the activity function
63+ # + T - The expected return type (inferred from context or explicitly specified)
64+ # + return - The result of the activity execution cast to type T, or an error if execution fails
65+ remote isolated function callActivity(function activityFunction , Parameters args , typedesc < anydata > T = <> )
66+ returns T | error = @java :Method {
67+ 'class : " io.ballerina.stdlib.workflow.context.WorkflowContextNative" ,
68+ name : " callActivity"
69+ } external ;
5770
5871 # Durable sleep that survives workflow restarts.
5972 #
@@ -98,15 +111,6 @@ public client class Context {
98111
99112// Native function declarations
100113
101- isolated function callActivityNative(
102- handle contextHandle ,
103- function activityFunction ,
104- anydata ... args
105- ) returns anydata | error = @java :Method {
106- 'class : " io.ballerina.stdlib.workflow.context.WorkflowContextNative" ,
107- name : " callActivity"
108- } external ;
109-
110114isolated function sleepNative(
111115 handle contextHandle ,
112116 int millis
0 commit comments