AI Briefing
KO

Improving Code Quality - Session 53: Dealing with Functions That Mix Excessive Notification Methods

·2025.11.14 11:00

Key point

Within a function, multiple asynchronous handling methods such as **Future** and **callback** should not be mixed; they should be unified into a single mechanism.

Details

When delivering the results of asynchronous processing to the caller, various methods can be used, such as return value, async/await, Promise/Future, or callback. However, if a single function uses both Future and asynchronous callback at the same time, it becomes hard to grasp when and how the result is delivered, which lowers code comprehensibility.

To improve code clarity, the asynchronous handling method should be limited to one per function. For example, instead of receiving a separate callback as an argument for error handling, it is recommended to use a sealed interface or similar to create a result object that includes both success and failure, and return it wrapped in a Future.

This approach allows the caller to flexibly manage success and error handling logic, and has the advantage of making it easier to ensure that the result-delivering function is called exactly once.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.