1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-20 04:41:36 +02:00

update readme part 1 of 2

This commit is contained in:
Thomas Wilkerling
2025-03-27 21:04:06 +01:00
parent 5abd01a3c5
commit 2b1771fd6d
12 changed files with 2745 additions and 2699 deletions

View File

@@ -2,9 +2,10 @@
> The async processing model is automatically observed by a runtime balancer to prevent any blocking issues, even on page load.
The most methods of each index type provides an async version, e.g.:
Those methods of each index type provides an async version:
- addAsync()
- ~~appendAsync()~~
- updateAsync()
- removeAsync()
- searchAsync()
@@ -13,6 +14,8 @@ All those async versions always return a `Promise`, although a callback can be p
When calling async methods of the index, a runtime balancer observe the current event loop and will pass to the next event loop automatically.
### Task Priority
You can control how early the process should move over to the next event loop by passing the option property `priority`:
```js
@@ -28,6 +31,8 @@ When you have some very smooth running animation you should use a priority of `2
On Node.js you can slightly increase this priority e.g. to `6`, because here there is no UI involved.
A priority value of `9` will cycle the event loop on every ~250ms which is the maximum recommended blocking time. You should not use a value higher than this.
### Polling Tasks
Do not forget to `await` on <u>every</u> async task you apply to the index:
```js
@@ -36,4 +41,44 @@ for(let i = 0; i < 99999999; i++){
}
```
You can perform queries to the index during any other async batch is running.
You can perform queries to the index during any other async batch is running.
### Examples
You can assign callbacks to each async function:
```js
index.addAsync(id, content, function(){
console.log("Task Done");
});
index.searchAsync(query, function(result){
console.log("Results: ", result);
});
```
Or do not pass a callback function and getting back a `Promise` instead:
```js
index.addAsync(id, content).then(function(){
console.log("Task Done");
});
index.searchAsync(query).then(function(result){
console.log("Results: ", result);
});
```
Or use `async` and `await`:
```js
async function add(){
await index.addAsync(id, content);
console.log("Task Done");
}
async function search(){
const results = await index.searchAsync(query);
console.log("Results: ", result);
}
```