Perform a parallel for:range loop

Uses a parallel for:range loop to translate text, specifying the beginning and end of an iteration range.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

YAML

  main 
 : 
  
 params 
 : 
  
 [] 
  
 steps 
 : 
  
 - 
  
 init 
 : 
  
 assign 
 : 
  
 - 
  
 workflow_id 
 : 
  
 "translate" 
  
 - 
  
 texts_to_translate 
 : 
  
 - 
  
 text 
 : 
  
 "hello 
  
 world!" 
  
 source 
 : 
  
 "en" 
  
 target 
 : 
  
 "fr" 
  
 - 
  
 text 
 : 
  
 "你好 
  
 世界!" 
  
 source 
 : 
  
 "zh-CN" 
  
 target 
 : 
  
 "en" 
  
 - 
  
 text 
 : 
  
 "No 
  
 hablo 
  
 español!" 
  
 source 
 : 
  
 "es" 
  
 target 
 : 
  
 "en" 
  
 - 
  
 translated 
 : 
  
 [ 
 "" 
 , 
  
 "" 
 , 
  
 "" 
 ] 
  
 # to write to this variable, you must share it 
  
 - 
  
 parallel_translate 
 : 
  
 parallel 
 : 
  
 shared 
 : 
  
 [ 
 translated 
 ] 
  
 for 
 : 
  
 range 
 : 
  
 ${[0, len(texts_to_translate) - 1]} 
  
 value 
 : 
  
 i 
  
 steps 
 : 
  
 - 
  
 translate 
 : 
  
 call 
 : 
  
 googleapis.workflowexecutions.v1.projects.locations.workflows.executions.run 
  
 args 
 : 
  
 workflow_id 
 : 
  
 ${workflow_id} 
  
 argument 
 : 
  
 ${texts_to_translate[i]} 
  
 result 
 : 
  
 r 
  
 - 
  
 set_result 
 : 
  
 assign 
 : 
  
 - 
  
 translated[i] 
 : 
  
 ${r} 
  
 - 
  
 return 
 : 
  
 return 
 : 
  
 ${translated} 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Create a Mobile Website
View Site in Mobile | Classic
Share by: