Are Hacklang Async / Awaitables hot or cold?

Date: 2022-10-26 | hack | hacklang | async


Overview

Async / Awaitables typically come in two flavors:

  • Hot - where they may start processing as soon as they're called (but typically not guaranteed to run/ finish until awaited)
  • Cold - where they will not start processing until awaited

Understanding the behavior of async processing in your language can be very important to better understand how to optimize your app for performance.

Are Hacklang Async / Awaitables hot or cold?

We can tell if an async process is hot by checking the behavior when an awaitable is declared but not awaited. In the case of hacklang, we see that the behavior is undefined (See: hacklang async documentation).

This means, once you call an async function / awaitable without the await keyword:

myAsyncFn();

The outcome of this could be:

  • myAsyncFn completes - all side effects finished
  • myAsyncFn is processing - some side effects finished
  • myAsyncFn never runs - no side effects finished

Because the outcome is undefined we know this is a hot task - as soon as you call it it may start running.

A cold task on the other hand does nothing until you explicitly tell it you want it to run - this is how async works in F# (See: F# - Core Concepts of Async).

-