Naming The Async Function - Part 2

March 15, 2024

Yet another better way to organize async functions in JavaScript utility function.

Previously, to be able to tell an async function at first glance, I put a Task prefix on the function name.

js
function TaskRefreshList() {
    // ...
}

Cons:

  • It makes the function name longer.
  • Doesn't make sense on a utility function that consist only async functions.

I think I've found a new way to organize async function without avoid above cons. All I had to do is to group async function as a task object.

js
let ui = (function() {
  
  let SELF = {
    task: {
      updateItem,
    }
  };
  
  function updateItem() {
    // todo()
  }

  return SELF;
  
})();

This way I can keep the name short but still able to tell async function or not.

Improving from Here

So, I ended up not using this approach as it requires me to selectively group async functions, which is quite a cumbersome process.

The next approach takes the initial writing and improves from it, i.e. by using "-Async" postfix instead of "Task-" prefix.

Continue to part 3.

Comments

Thank You

for your visit