Expo Module DSL in Kotlin and Swift
Prerequisites: 03-module-interface-map, 04-platform-ownership
Definition to runtime
Sync versus async
Mental model verified
Name exposes the JS module. Function is synchronous; AsyncFunction returns a Promise. View defines a native visual component, Events declares signals, and lifecycle hooks observe module/app/activity changes. Expo handles much of the type conversion.
[S12] [S11]Worked flow synthesis
A payment scanner wrapper might expose Function("isSupported") for a small cached Boolean and AsyncFunction("scanAsync") for SDK work. Both Kotlin and Swift implement the contract; the exact SDK calls and error types are platform-specific. This is pseudocode, not a complete module.
[S12]Engineering decision verified
Use AsyncFunction for I/O or long work. Explicitly dispatch UI-related operations to the main queue; do not assume an arbitrary async native function is on main. Keep a TS facade that maps platform errors to stable results.
[S12]Failure mode and improvement verified
JavaScriptValue is tied to the JS runtime thread. Do not capture it into AsyncFunction worker work; convert it first or use a native shared object with a defined lifetime.
[S12] [S13]Check yourself: What is the difference between Function and AsyncFunction?
Function runs synchronously on the JS caller thread; AsyncFunction returns a Promise and normally dispatches native work away from it.