-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Is your feature request related to a problem? Please describe.
Currently, all functions in AutoIt JS are synchronous. This works well (and is often preferable) for simple scripting tasks, but becomes problematic in asynchronous environments like Playwright or Cypress tests where blocking behavior can hinder performance or test stability.
Describe the solution you'd like
Koffi allows for calling functions asynchronously via callback functions so the core change would just be adding an invokeAsync
method in the AutoIt
class. This part is easy but the overwhelming majority of the work will be writing all the asynchronous variants of the existing synchronous functions.
The plan is:
- Rename all current functions to include the
Sync
suffix - Re-export async variants using the original, non-suffixed names
This follows Node.js conventions (e.g., fs.stat
vs fs.statSync
) where async is the default unless specified otherwise. Because this involves renaming over 100 functions, it will be released as a major version bump.
Example:
import { WinGetTitle, WinGetTitleSync } from '@ahmic/autoit-js';
const title = await WinGetTitle(...);
const titleSync = WinGetTitleSync(...);
Describe alternatives you've considered
-
Dynamic sync/async detection: Attempted to infer whether a function should run sync or async based on how it's called, but JavaScript/Node/V8 provides no reliable way to determine if await was used.
-
Shared implementation with dispatching logic: Tried building a common core implementation that chooses between sync and async based on parameters, but the variance in buffer handling and return values across functions made this to annoying to deal with.
Additional context
It'll be important to handle the Win32 functions asynchronously as well when creating async variants of the custom re-implemented functions like Tooltip
and PixelSearch
.
The work will be done on the async-implementation branch.