What are futures?

后端 未结 7 1725
梦毁少年i
梦毁少年i 2021-02-13 09:29

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

7条回答
  •  别跟我提以往
    2021-02-13 10:23

    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.

提交回复
热议问题