What are futures?

后端 未结 7 1195
长发绾君心
长发绾君心 2021-02-13 09:37

What are futures? It\'s something to do with lazy evaluation.

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-13 10:04

    When you create a future, a new background thread is started that begins calculating the real value. If you request the value of the future, it will block until the thread has finished calculating. This is very useful for when you need to generate some values in parallel and don't want to manually keep track of it all.

    See lazy.rb for Ruby, or Scala, futures, and lazy evaluation.

    They can probably be implemented in any language with threads, though it would obviously be more difficult in a low-level language like C than in a high-level functional language.

提交回复
热议问题