### Install Production Dependencies Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Navigates to the project root and installs production dependencies. ```bash cd ../../; npm i --production; cd ../../ ``` -------------------------------- ### Install Dependencies Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Installs project dependencies using npm. ```bash npm i ``` -------------------------------- ### Install Debug Version to Device Source: https://github.com/aiselp/autox/blob/setup-v7/README.md Builds a debug template app, assembles the v7 debug APK, and installs it on a connected device. ```shell ./gradlew app:buildDebugTemplateApp && ./gradlew app:assembleV7Debug && ./gradlew app:installV7Debug ``` ```shell ./gradlew app:buildDebugTemplateApp ; ./gradlew app:assembleV7Debug ; ./gradlew app:installV7Debug ``` -------------------------------- ### Install Lodash using npm Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/README.md Install Lodash globally and as a project dependency using npm. ```shell $ npm i -g npm $ npm i --save lodash ``` -------------------------------- ### Manual Bootstrapping of Bluebird-co Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Manually add the bluebird-co yield handler to Bluebird for more control. This requires installing both bluebird and bluebird-co. ```javascript var Promise = require('bluebird'), bluebird_co = require('bluebird-co/manual'); Promise.coroutine.addYieldHandler(bluebird_co.toPromise); var fn = Promise.coroutine(function*(){ //do stuff }); fn().then(...); ``` -------------------------------- ### Async/Await Coroutine Example with Bluebird Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md An ES7 async function example that mirrors the generator coroutine. It uses await for promises and demonstrates yielding various types. ```javascript import Promise from 'bluebird'; import {readFile} from 'fs'; let readFileAsync = Promise.promisify(readFile); async function myAsyncFunction() { let results = await [Promise.delay( 10 ).return( 42 ), readFileAsync( 'index.js', 'utf-8' ), [1, Promise.resolve( 12 )]]; console.log(results); //[42, "somefile contents", [1, 12]] } myAsyncFunction().then(...); ``` -------------------------------- ### Generator Coroutine Example with Bluebird Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md An example of a generator coroutine using Bluebird. This snippet demonstrates yielding arrays of promises, file reads, and nested arrays. ```javascript var Promise = require('bluebird'); var fs = Promise.promisifyAll(require('fs')); var myAsyncFunction = Promise.coroutine(function*() { var results = yield [Promise.delay( 10 ).return( 42 ), readFileAsync( 'index.js', 'utf-8' ), [1, Promise.resolve( 12 )]]; console.log(results); //[42, "somefile contents", [1, 12]] }); myAsyncFunction().then(...); ``` -------------------------------- ### Automatic Bootstrapping of Bluebird-co Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Use this snippet to automatically integrate bluebird-co's yield handlers into Bluebird. Ensure Bluebird is installed as a peer dependency. ```javascript require('bluebird-co'); ``` -------------------------------- ### Traverse a Set with Asynchronous Values Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md This example demonstrates how to traverse a JavaScript Set containing promises and other nested structures. The 'bluebird-co' library automatically resolves asynchronous values during traversal. ```javascript let mySet = new Set( [Promise.resolve( 1 ), 2, [Promise.resolve( 3 ), 4], 5] ); async function() { let values = await mySet.values(); console.log(values); //[1, 2, [3, 4], 5] } ``` -------------------------------- ### Manually Iterate Through a Set's Values Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md This code shows the manual iteration process for a JavaScript Set using its iterator. It demonstrates how to get each value sequentially until the iterator is done. ```javascript let mySet = new Set([1, 2, 3, 4]); let values = mySet.values(); let cur = values.next(); //Prints out 1 2 3 4 while(!cur.done) { console.log(cur.value); cur = values.next(); } ``` -------------------------------- ### Define a Simple Generator Function Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md Use this function to yield promises for a specified number of iterations. It's a basic example of generator functionality. ```javascript function* test(iterations){ let i = 0; while(i++ < iterations) { yield Promise.resolve(i); } } ``` -------------------------------- ### Get Single Argument Thunk Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md Defines a thunk function that returns a value. This is useful for simple asynchronous operations where a single result is expected. ```javascript function get(value) { return function(done) { done(null, value); } } async function() { let value = await get(10); console.log(value); //10 } ``` -------------------------------- ### Deep Error Handling with Iteration Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md Shows how to handle errors that occur deep within asynchronous operations after a significant number of iterations. This example includes a conditional throw based on an iteration count. ```javascript //deep error async function() { let i = 0; await function*() { if(i++ > 2000) throw new Error(); yield Promise.resolve(i); } } ``` -------------------------------- ### Build Documentation Source: https://github.com/aiselp/autox/blob/setup-v7/README.md Run this command once to compile documentation. Re-run if documentation content changes. ```shell ./gradlew app:buildDocs ``` -------------------------------- ### Prepare Temporary Directory for Release Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Creates a temporary directory and copies build artifacts into it. ```bash mkdir ../lodash-temp cp lodash.js dist/lodash.min.js dist/lodash.core.js dist/lodash.core.min.js ../lodash-temp/ ``` -------------------------------- ### Build Project Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Builds the project using npm. ```bash npm run build ``` -------------------------------- ### Generate Documentation Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Generates project documentation using npm. ```bash npm run doc ``` -------------------------------- ### Build and Sign Release Version in Android Studio Source: https://github.com/aiselp/autox/blob/setup-v7/README.md First, build the template app. Then, use Android Studio's 'Generate Signed Bundle / APK' feature to sign and build the release version. ```shell ./gradlew app:buildTemplateApp ``` -------------------------------- ### Copy LICENSE Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Copies the LICENSE file to the npm-package directory. ```bash cp LICENSE npm-package/LICENSE ``` -------------------------------- ### Build Release Version Source: https://github.com/aiselp/autox/blob/setup-v7/README.md Builds a release template app and assembles the v7 release APK. The output is an unsigned APK. ```shell ./gradlew app:buildTemplateApp && ./gradlew app:assembleV7 ``` ```shell ./gradlew app:buildTemplateApp ; ./gradlew app:assembleV7 ``` -------------------------------- ### Configure Paddle Lite and OpenCV Paths Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Sets the directory variables for Paddle Lite and OpenCV, and includes their header files. Ensure these paths are correct relative to your project structure. ```cmake set(PaddleLite_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../PaddleLite") include_directories(${PaddleLite_DIR}/cxx/include) ``` ```cmake set(OpenCV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../OpenCV/sdk/native/jni") message(STATUS "opencv dir: ${OpenCV_DIR}") find_package(OpenCV REQUIRED) message(STATUS "OpenCV libraries: ${OpenCV_LIBS}") include_directories(${OpenCV_INCLUDE_DIRS}) ``` -------------------------------- ### Prepare lodash-cli Node Modules Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Creates a directory for lodash within lodash-cli's node modules and copies lodash source files. ```bash mkdir -p ./node_modules/lodash-cli/node_modules/lodash; cd $_; cp ../../../../lodash.js ./lodash.js; cp ../../../../package.json ./package.json ``` -------------------------------- ### Import Paddle Lite Shared Library Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Imports the prebuilt Paddle Lite shared library. This allows linking against it without compiling its sources. ```cmake add_library( # Sets the name of the library. paddle_light_api_shared # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). IMPORTED) set_target_properties( # Specifies the target library. paddle_light_api_shared # Specifies the parameter you want to define. PROPERTIES IMPORTED_LOCATION ${PaddleLite_DIR}/cxx/libs/${ANDROID_ABI}/libpaddle_light_api_shared.so # Provides the path to the library you want to import. ) ``` -------------------------------- ### Run Script Tests Source: https://github.com/aiselp/autox/blob/setup-v7/README.md Steps to run script function tests: connect an Android device, build the autojs module, open a test class in `autojs/src/androidTest`, and run the test from Android Studio. ```shell ./gradlew autojs:assemble ``` -------------------------------- ### Build lodash Core with lodash-cli Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Uses lodash-cli to build the core lodash module and output to a specific file. ```bash node ../lodash-cli/bin/lodash core -o ./dist/lodash.core.js ``` -------------------------------- ### Benchmark: Asynchronous Promise Resolution Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md This snippet demonstrates the basic usage of `await` with a resolved promise. It's used to benchmark raw promise handling. ```javascript async function() { let res = await Promise.resolve(1); console.log(res); //1 } ``` -------------------------------- ### Load Lodash in Node.js Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/README.md Demonstrates various ways to load Lodash modules in Node.js, including the full build, core build, FP build, method categories, and cherry-picked methods. ```javascript // Load the full build. var _ = require('lodash'); ``` ```javascript // Load the core build. var _ = require('lodash/core'); ``` ```javascript // Load the FP build for immutable auto-curried iteratee-first data-last methods. var fp = require('lodash/fp'); ``` ```javascript // Load method categories. var array = require('lodash/array'); var object = require('lodash/fp/object'); ``` ```javascript // Cherry-pick methods for smaller browserify/rollup/webpack bundles. var at = require('lodash/at'); var curryN = require('lodash/fp/curryN'); ``` -------------------------------- ### Compile JS Module Source: https://github.com/aiselp/autox/blob/setup-v7/README.md Run this command once to compile JS modules before building. Requires Node.js 20+. ```shell ./gradlew autojs:buildJsModule ``` -------------------------------- ### Copy Release Artifacts Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Copies core and minified lodash files from the temporary directory to the root. ```bash cp ../lodash-temp/lodash.core.js core.js cp ../lodash-temp/lodash.core.min.js core.min.js cp ../lodash-temp/lodash.js lodash.js cp ../lodash-temp/lodash.min.js lodash.min.js ``` -------------------------------- ### Run Debug Version in Android Studio Source: https://github.com/aiselp/autox/blob/setup-v7/README.md First, build the debug template app, then run the debug version from Android Studio. ```shell ./gradlew app:buildDebugTemplateApp ``` -------------------------------- ### Benchmark: Asynchronous Object Handling Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md This snippet illustrates using `await` with an object containing asynchronous operations. It's used to benchmark performance with objects of varying key counts. ```javascript async function() { let res = await { a: asyncFunc1(), b: asyncFunc2(), c: somePromise, d: 42 }; } ``` -------------------------------- ### Build lodash Core Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Uses lodash-cli to build the core lodash module for Node.js. ```bash node ./node_modules/lodash-cli/bin/lodash core exports=node -o ./npm-package/core.js ``` -------------------------------- ### Copy Shared Libraries Post-Build Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Uses custom commands to copy essential shared libraries (libc++_shared.so, libpaddle_light_api_shared.so, libhiai.so, etc.) to the library output directory after the main 'Native' library is built. This ensures all dependencies are available. ```cmake add_custom_command( TARGET Native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PaddleLite_DIR}/cxx/libs/${ANDROID_ABI}/libc++_shared.so ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libc++_shared.so) add_custom_command( TARGET Native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PaddleLite_DIR}/cxx/libs/${ANDROID_ABI}/libpaddle_light_api_shared.so ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpaddle_light_api_shared.so) add_custom_command( TARGET Native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PaddleLite_DIR}/cxx/libs/${ANDROID_ABI}/libhiai.so ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libhiai.so) add_custom_command( TARGET Native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PaddleLite_DIR}/cxx/libs/${ANDROID_ABI}/libhiai_ir.so ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libhiai_ir.so) add_custom_command( TARGET Native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PaddleLite_DIR}/cxx/libs/${ANDROID_ABI}/libhiai_ir_build.so ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libhiai_ir_build.so) ``` -------------------------------- ### tj/co Drop-in Replacement Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Import and use `co` and `co.wrap` directly from bluebird-co, providing a drop-in replacement for the tj/co library. ```javascript import {co} from 'bluebird-co'; co(...); co.wrap(...); ``` -------------------------------- ### Benchmark: Asynchronous Array Handling Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md This snippet shows how to use `await` with an array of asynchronous operations. It's used to benchmark performance with arrays of varying sizes. ```javascript async function() { let res = await [asyncFunc1(), asyncFunc2(), somePromise, 42]; } ``` -------------------------------- ### Copy lodash.min.js Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Copies the minified lodash.js file to the npm-package directory. ```bash cp dist/lodash.min.js npm-package/lodash.min.js ``` -------------------------------- ### Clone lodash and lodash-cli Repositories Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Clones the lodash and lodash-cli repositories from GitHub. ```bash git clone https://github.com/lodash/lodash.git ``` ```bash git clone https://github.com/bnjmnt4n/lodash-cli.git ``` -------------------------------- ### Babel 6 Configuration for Async/Await Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Configure Babel 6 to use bluebird-co for transforming async functions into coroutines. This allows for seamless async/await syntax. ```json { "plugins": [ ["transform-async-to-module-method", { "module": "bluebird-co", "method": "coroutine" }] ] } ``` -------------------------------- ### Copy lodash.js Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Copies the lodash.js file to the npm-package directory. ```bash cp lodash.js npm-package/lodash.js ``` -------------------------------- ### Link Libraries to Native Target Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Links the 'Native' library with other required libraries, including the imported Paddle Lite library, OpenCV, and system libraries like GLESv2, EGL, jnigraphics, and log. ```cmake target_link_libraries( # Specifies the target library. Native paddle_light_api_shared ${OpenCV_LIBS} GLESv2 EGL jnigraphics ${log-lib}) ``` -------------------------------- ### Modularize lodash Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Uses lodash-cli to modularize lodash for Node.js. ```bash node ./node_modules/lodash-cli/bin/lodash modularize exports=node -o ./npm-package ``` -------------------------------- ### .execute(gfn, ...args) / .co(gfn, ...args) Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Executes a generator function or generator object, returning a Promise. This is a drop-in replacement for tj/co's co function. ```APIDOC ## .execute(gfn : `[`GeneratorFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction)`|`[`Generator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator)`, ...args : any[]) -> Promise **alias**: `.co(gfn : `[`GeneratorFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction)`|`[`Generator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator)`, ...args : any[])` -> `Promise` This calls [`.coroutine`](), then invokes the resulting function with the arguments provided, or just runs the generator object directly. It is meant as a drop in replacement for tj/co `co`, like so: ```javascript //import {co} from 'bluebird-co'; var co = require('bluebird-co').co; function* do_stuff(num) { return num; } co(do_stuff, 10).then(function(result){ console.log(result); //10 }); ``` ``` -------------------------------- ### Utility Functions Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md This section covers various utility functions provided by the bluebird-co library for checking object types and managing yield handlers. ```APIDOC ## .coroutine.yieldHanlders -> Array ### Description Exposes all custom yield handlers that have been added. bluebird-co expects this to be an array, so don't overwrite it with something silly. ### Method Getter ### Endpoint N/A (Internal property) ### Parameters None ### Request Example None ### Response #### Success Response (200) - `Array` - An array of custom yield handlers. ### Response Example None ``` ```APIDOC ## .isThenable(value : any) -> boolean ### Description Checks if the provided value is a promise-like object (has a `then` function). ### Method GET ### Endpoint N/A (Utility function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - `boolean` - `true` if the value is thenable, `false` otherwise. ### Response Example None ``` ```APIDOC ## .isPromise(value : any) -> boolean ### Description Alias for `.isThenable`. Checks if the provided value is a promise-like object. ### Method GET ### Endpoint N/A (Utility function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - `boolean` - `true` if the value is a promise, `false` otherwise. ### Response Example None ``` ```APIDOC ## .isGenerator(value : any) -> boolean ### Description Checks if the value is a generator instance with `.next` and `.throw` methods. ### Method GET ### Endpoint N/A (Utility function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - `boolean` - `true` if the value is a generator instance, `false` otherwise. ### Response Example None ``` ```APIDOC ## .isGeneratorFunction(value : any) -> boolean ### Description Checks if the value is a [`GeneratorFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction). ### Method GET ### Endpoint N/A (Utility function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - `boolean` - `true` if the value is a GeneratorFunction, `false` otherwise. ### Response Example None ``` -------------------------------- ### .coroutine(gfn) / .wrap(gfn) Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Creates a coroutine function from a generator function, similar to Bluebird.coroutine. The .wrap alias provides compatibility with co.wrap. ```APIDOC ## .coroutine(gfn : `[`GeneratorFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction)`) -> Function **alias**: `.wrap(gfn : `[`GeneratorFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction)`)` -> `Function` **alias**: `.co.wrap(gfn : `[`GeneratorFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction)`)` -> `Function` This calls [Bluebird.coroutine](http://bluebirdjs.com/docs/api/promise.coroutine.html) and returns the resulting function. When called, the returned function will return a Promise. The `.wrap` alias is provided to be a drop-in replacement for `co.wrap`. ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Specifies the minimum CMake version required for the build. Ensure your environment meets this version. ```cmake cmake_minimum_required(VERSION 3.4.1) ``` -------------------------------- ### .addYieldHandler(fn) Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Adds a custom function to handle specific types when yielding. This function is similar to Bluebird's addYieldHandler and allows for custom type processing. ```APIDOC ## .addYieldHandler(fn : Function) **alias**: `.coroutine.addYieldHandler(fn : Function)` Very similar to [Bluebird.coroutine.addYieldHandler](http://bluebirdjs.com/docs/api/promise.coroutine.addyieldhandler.html), `.addYieldHandler` allows custom types to be processed by bluebird-co in conjunction with any other yieldable types, even other custom yield handlers. This includes nested yieldable types. Aside from the [caveats](#caveats) of `Object` types when using custom yield handlers, any other type or value can be handled, even null, undefined, Symbols, anything. However, built-in yield handlers cannot be overridden. See the above section on [Custom yieldable types](#custom-yieldable-types) for an example. ``` -------------------------------- ### Clone lodash-cli Repository Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Clones the lodash-cli repository with a specific depth and branch. ```bash git clone --depth=10 --branch=master git@github.com:lodash-archive/lodash-cli.git ./node_modules/lodash-cli ``` -------------------------------- ### Custom Yieldable Types Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Demonstrates how to add custom yield handlers to bluebird-co to support application-specific types. ```APIDOC ## Custom Yieldable Types It may become desirable to add custom yield handling for types not listed above based on the needs of a certain application. To make this easy, bluebird-co provides an analogue to Bluebird's [Bluebird.coroutine.addYieldHandler](http://bluebirdjs.com/docs/api/promise.coroutine.addyieldhandler.html) that works together in combination with the above yield handlers. To do this, bluebird-co provides the [`.coroutine.addYieldHandler(fn)`](#addyieldhandlerfn--function) function, or just [`.addYieldHandler(fn)`](#addyieldhandlerfn--function) for short. The first is for strict compatibility with Bluebird. Example of automatically fetching model data by yielding the model instance: ```javascript import {coroutine} from 'bluebird-co'; class MyModel { async fetch() { //do stuff return data; } } coroutine.addYieldHandler(function(value) { if(value instanceof MyModel) { return value.fetch(); } }); async function test() { let model = new MyModel(); let data = await model; //calls model.fetch() and waits on it. } ``` Additionally, you can even access the array of yield handlers manually if you ever need to remove one, like so: ```javascript console.log(coroutine.yieldHandlers); //array of functions ``` #### Caveats: Although this works for most classes and even null, it will **NOT** work if the class inherits from `Object` or if `Object` is in the prototype chain for the value's constructor. If it inherits from `Object`, it will be considered an `Object` instance and processed like any other object. Values without any `constructor` property will be considered an `Object`, as well. ``` -------------------------------- ### Modularize lodash for ES Modules Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/lodash/release.md Uses lodash-cli to modularize lodash for ES module exports. ```bash node ../lodash-cli/bin/lodash modularize exports=es -o . ``` -------------------------------- ### .toPromise(value) Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Converts a given value, including supported yieldable types, into a Promise. If the value cannot be converted, the original value is returned. ```APIDOC ## .toPromise(value : any) -> Promise | any `toPromise` is the central function of bluebird-co. It takes any of the supported yieldable types (and those added via [`.addYieldHandler`](#addyieldhandlerfn--function)), and attempts to convert it to a Promise. Any Promises within the value are resolved before the returned Promise resolves. In the event that the given value cannot be transformed into a Promise, like when it is not in the possible yieldable types, the original value is returned. When used in conjunction with Bluebird coroutines, Bluebird will throw an error because the value is not a Promise instance. ``` -------------------------------- ### Execute Generator Function with co Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Use the `co` function as a drop-in replacement for tj/co to execute a generator function and return a Promise. It accepts the generator function and its arguments. ```javascript //import {co} from 'bluebird-co'; var co = require('bluebird-co').co; function* do_stuff(num) { return num; } co(do_stuff, 10).then(function(result){ console.log(result); //10 }); ``` -------------------------------- ### Top-Level Error Handling Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md Demonstrates handling errors at the top level of an async function. This is the most basic form of error handling. ```javascript //Top level error async function() { await undefined; } ``` -------------------------------- ### Define Native Shared Library Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Defines the main native shared library named 'Native'. It compiles the source files found in the current directory. ```cmake aux_source_directory(. SOURCES) add_library( # Sets the name of the library. Native # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). ${SOURCES}) find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that you want CMake to locate. log) ``` -------------------------------- ### Add Custom Yield Handler for MyModel Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Register a custom yield handler to automatically fetch data when a MyModel instance is yielded. This allows awaiting custom objects directly. ```javascript import {coroutine} from 'bluebird-co'; class MyModel { async fetch() { //do stuff return data; } } coroutine.addYieldHandler(function(value) { if(value instanceof MyModel) { return value.fetch(); } }); async function test() { let model = new MyModel(); let data = await model; //calls model.fetch() and waits on it. } ``` -------------------------------- ### Set C++ Compiler Flags Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Configures C++ compiler flags for optimization and visibility. These flags affect build performance and binary size. ```cmake set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -Ofast -Os" ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections -ffunction-sections" ) ``` -------------------------------- ### Nested Error Handling Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md Illustrates error handling within a nested asynchronous structure, such as a generator function yielding promises. ```javascript //nested error async function() { await function*() { yield undefined; } } ``` -------------------------------- ### Set Shared Linker Flags Source: https://github.com/aiselp/autox/blob/setup-v7/paddleocr/src/main/cpp/CMakeLists.txt Configures shared linker flags for section garbage collection and relocation. These flags optimize the final shared library. ```cmake set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,-z,nocopyreloc") ``` -------------------------------- ### Access Yield Handlers Array Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Retrieve the array of currently registered yield handlers. This can be useful for inspection or manual manipulation if needed. ```javascript console.log(coroutine.yieldHandlers); //array of functions ``` -------------------------------- ### Check if a value is thenable in JavaScript Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/README.md Use this function to determine if a given value has a `.then` method, indicating it might be a Promise or a thenable object. Ensure the value is not null or undefined before checking. ```javascript function isThenable(value) { return value && typeof value.then === 'function'; } ``` -------------------------------- ### Define a Complex Generator Function Source: https://github.com/aiselp/autox/blob/setup-v7/autojs/src/main/assets/modules/npm/bluebird-co/benchmark/README.md This generator yields nested structures including promises and arrays, demonstrating more advanced generator capabilities. It requires careful handling of yielded values. ```javascript function* complex_generator( iterations ) { let test3 = new Array( iterations ); for( let i = 0; i < iterations; i++ ) { test3[i] = Promise.resolve( i ); } for( let i = 0; i < iterations; i++ ) { yield [yield Promise.resolve( i ), { test: yield Promise.resolve( i ), test2: Promise.resolve( i + 1 ), test3: test3 }]; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.