4

What is the use of the yield keyword in Julia and what does it do? I have seen it used a few times in Python and then in Julia but it seems to be used in very different contexts in Julia.

logankilpatrick
  • 13,148
  • 7
  • 44
  • 125

1 Answers1

5

Unlike in Python, where the yield keyword function similar to the return keyword but for generators, the yield keyword function in Julia is part of the tasks interface. From the docs:

yield()

Switch to the scheduler to allow another scheduled task to run. A task that calls this function is still runnable, and will be restarted immediately if there are no other runnable tasks.

logankilpatrick
  • 13,148
  • 7
  • 44
  • 125