jamiebuilds / ghost-lang

:ghost: A friendly little language for you and me.
302 stars 10 forks source link

Do blocks should inherit `async` modifier #10

Closed aleclarson closed 6 years ago

aleclarson commented 6 years ago

Do blocks should inherit async modifier from their function context, because do blocks are not functions themselves.

let foo = async fn (a, b) {
  let bar = do {
    await fetchSomething()
  }
}
jamiebuilds commented 6 years ago

They are two different things, a do async can be used within a function to create concurrent code.

let fn = async fn () {
  let value = do {
    await sleep(100)
    42
  }
  assert(value is 42)
}
let fn = async fn () {
  let value = do async {
    await sleep(100)
    42
  }
  assert(value is Async<42>)
}
jamiebuilds commented 6 years ago

You're determining with block the await belongs to

aleclarson commented 6 years ago

Oh okay. Very cool. Maybe a comparison of both should be in the readme?

aleclarson commented 6 years ago

Need more docs about Async too! :)