Hello,
I am newbie in Julia. I am writing a small program which reads topics/records from Apache Kafka, process it and writes as another topic back.
My main function which is in main.jl file is as follows. There are basically three small modules, specifically one reads from kafka, another writes to kafka, the other is the processing task which is called algorithm. It is supposed to make some calculations and report back the result.
Modules communicate via channels. main.jl just initializes the modules with appropriate channels. Init interfaces of the modules return tasks which consist of infinite loop that reads, writes to kafka and do processing etc.
Init functions of these modules return tasks which are created via @async. I expect @sync to block on these tasks which are listed between begin ... end
block. However, the main function returns and the tasks dies, before the previously created tasks. I tried yiedto one of the previously created tasks, wrapping init calls in anonymous functions, tuples, you name it. Only map
function that is commented out below works. However it is counter intuitive and I would like to understand why @sync does not work as it is supposed to?
What is wrong with this code? Any help much appreciated.
main.jl file
include("kafka_consumer.jl")
include("kafka_producer.jl")
include("algorithm.jl")
import .TPRROKafkaConsumer as cons
import .TPRROKafkaProducer as prod
import .TPRROAlgorithm as alg
const input_channel_size = 100;
const output_channel_size = 100;
function main()
input_channel = Channel{Dict}(input_channel_size)
output_channel = Channel{Dict}(output_channel_size)
@sync begin
cons.init(input_channel)
prod.init(output_channel)
alg.init(input_channel, output_channel)
end
#=
map(wait,[cons.init(input_channel),
prod.init(output_channel),
alg.init(input_channel, output_channel)])
=#
end
main()