LynxMainThread
A service that calls one of your main-thread scripts from Angular code, and gives you its return value. import { LynxMainThread } from '@blotch/angular-lynx';
Info
Template handlers such as (bindtap) already run on the main thread. Main-thread scripts explains when you need this API instead.
Usage
src/app/app.ts
LynxMainThread is provided in root, so inject() it anywhere.
API
runOnMainThread(handle, ...args)
handle: a function frommainThreadFn().args: its arguments, checked against its parameter types.- Returns a promise of the function's return value. It rejects if the function throws or its promise rejects.
It runs the function right away. Your Angular code runs on the main thread, where the function is, so the call doesn't cross threads: arguments aren't copied, and a returned promise is awaited. Call it from anywhere in your app, such as an event handler, a constructor or an effect().
Related
- Main-thread scripts guide
mainThreadFnbackgroundFn: the other direction
