Loading...
Searching...
No Matches
js_event_loop.h File Reference

In JS interpreter code, js_event_loop always creates and maintains the event loop. More...

#include "../../js_modules.h"
#include <furi/core/event_loop.h>
#include <furi/core/event_loop_timer.h>

Go to the source code of this file.

Data Structures

struct  JsEventLoopNonTimerContract
 
struct  JsEventLoopTimerContract
 
struct  JsEventLoopContract
 Adapter for other JS modules that wish to integrate with the event loop JS module. More...
 

Typedefs

typedef struct JsEventLoop JsEventLoop
 
typedef mjs_val_t(* JsEventLoopTransformer) (struct mjs *mjs, FuriEventLoopObject *object, void *context)
 

Enumerations

enum  JsEventLoopObjectType {
  JsEventLoopObjectTypeTimer , JsEventLoopObjectTypeQueue , JsEventLoopObjectTypeMutex , JsEventLoopObjectTypeSemaphore ,
  JsEventLoopObjectTypeStream
}
 

Functions

FuriEventLoopjs_event_loop_get_loop (JsEventLoop *loop)
 Gets the FuriEventLoop owned by a JsEventLoop.
 

Detailed Description

In JS interpreter code, js_event_loop always creates and maintains the event loop.

There are two ways in which other modules can integrate with this loop:

  • Via contracts: The user of your module would have to acquire an opaque JS value from you and pass it to js_event_loop. This is useful for events that they user may be interested in. For more info, look at JsEventLoopContract. Also look at js_event_loop_get_loop, which you will need to unsubscribe the event loop from your object.
  • Directly: When your module is created, you can acquire an instance of JsEventLoop which you can use to acquire an instance of FuriEventLoop that you can manipulate directly, without the JS programmer having to pass contracts around. This is useful for "behind-the-scenes" events that the user does not need to know about. For more info, look at js_event_loop_get_loop.

In both cases, your module is responsible for both instantiating, unsubscribing and freeing the object that the event loop subscribes to.

Function Documentation

◆ js_event_loop_get_loop()

FuriEventLoop * js_event_loop_get_loop ( JsEventLoop * loop)

Gets the FuriEventLoop owned by a JsEventLoop.

This function is useful in case your JS module wishes to integrate with the event loop without passing contracts through JS code. Your module will be dynamically linked to this one if you use this function, but only if JS code imports event_loop before your module. An instance of JsEventLoop may be obtained via js_module_get.