Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

@Retention(CLASS) @Target({METHOD})

public @interface JavaScriptDetached

Marks a void method whose callers never wait for it to finish, so the JavaScript port may let it finish later.

On the web, a method that can wait – through Object.wait(), Thread.sleep(), invokeAndBlock(), or any call or interface method that leads to one – becomes a JavaScript generator, and so does every method that calls it. A method that hands work off and returns, like Display.callSerially(Runnable), carries that cost to every caller only because one rarely taken path runs the work in place.

With this annotation the JavaScript port runs the method as an ordinary function. Its body runs synchronously, exactly as written, until the first point where it would really wait; from there the rest of it continues on a new green thread and the caller returns. Nothing that calls the method becomes a generator because of it. When the body never waits, nothing changes at all. A caller that is a generator anyway may still run the body in place and wait for it, as it does today for a private method. Every other platform ignores the annotation.

Use it only on a method whose contract already says it returns without waiting for the work it starts: anything its caller does next must not depend on the body having finished. A method with a mode that waits does not qualify: EventDispatcher’s off-EDT delivery waits for the listeners when the dispatcher is blocking, and NetworkManager reads isConsumed() straight after it.

Before Codename One starts, Display.callSerially runs its runnable in place. If that runnable waits, the rest of it now finishes on its own green thread, and anything it throws from there reaches the uncaught-exception handler rather than the caller.