1 /** 2 A protocol for any type-erased module that provides functions used by the core. 3 */ 4 public protocol AnyModule: AnyObject, AnyArgument { 5 /** 6 The default initializer. Must be public, but the module class does *not* need to 7 define it as it is implemented in protocol composition, see `BaseModule` class. 8 */ 9 init(appContext: AppContext) 10 11 /** 12 A DSL-like function that returns a `ModuleDefinition` which can be built up from module's name, constants or functions. 13 The `@ModuleDefinitionBuilder` wrapper is *not* required in the implementation — it is implicitly taken from the protocol. 14 15 # Example 16 17 ``` definitionnull18 public func definition() -> ModuleDefinition { 19 Name("MyModule") 20 AsyncFunction("myFunction") { (a: String, b: String) in 21 "\(a) \(b)" 22 } 23 } 24 ``` 25 26 This example exports the module to the JavaScript world, which can be used as in this snippet 27 28 ```javascript 29 import { NativeModulesProxy } from 'expo-modules-core'; 30 31 await NativeModulesProxy.MyModule.myFunction('Hello', 'World!'); // -> 'Hello World!' 32 ``` 33 34 # Function's result obtained asynchronously 35 36 If you need to run some async code to get the proper value that you want to return to JavaScript, 37 just specify an argument of type `Promise` as the last one and use its `resolve` or `reject` functions. 38 39 ``` 40 AsyncFunction("myFunction") { (promise: Promise) in 41 DispatchQueue.main.async { 42 promise.resolve("return value obtained in async callback") 43 } 44 } 45 ``` 46 */ 47 #if swift(>=5.4) 48 @ModuleDefinitionBuilder 49 func definition() -> ModuleDefinition 50 #else 51 func definition() -> ModuleDefinition 52 #endif 53 } 54