doc-push icon indicating copy to clipboard operation
doc-push copied to clipboard

Getting started: define "task"

Open nrc opened this issue 7 years ago • 6 comments

"task" is used without definition, and it's a bit confusing what exactly it is - does it have a precise, technical meaning or is it colloquial? Is it the same as a future or a combination of futures or something else?

nrc avatar Oct 27 '18 08:10 nrc

In particular, "task" seems to mean something different in 'hello world' c.f., 'polling model'.

nrc avatar Oct 27 '18 08:10 nrc

This is still an issue. It seems that we sometimes use the term "task" when we simply mean "future". "Task" should probably only refer to futures that are spawned onto the runtime. @carllerche Do you have a better, clearer picture of when it's appropriate to use each term?

rylev avatar Nov 25 '18 20:11 rylev

Maybe instead of just calling things a "task", we could call them "future spawned as a task"? It is longer though.

carllerche avatar Nov 26 '18 05:11 carllerche

I think that just punts the question along. What does it mean to be spawned as a task?

rylev avatar Nov 26 '18 16:11 rylev

It does... but it at least differentiates between future & task. A task is a unit of execution managed by an executor and it is represented by a Future.

carllerche avatar Nov 26 '18 17:11 carllerche

I think of a task as just a spawned future running inside an executor.

Perhaps a good analogy could be threads and closures. Consider:

  • thread::spawn(|| println!("hello"))
  • tokio::spawn(lazy(|| { println!("hello"); ok(()) }))

The analogy goes like this:

  • thread::spawn = tokio::spawn
  • closure = future
  • thread = task
  • spawned closure is a thread = spawned future is a task

ghost avatar Nov 29 '18 19:11 ghost