Skip to content

Commit

Permalink
Adjust spelling in readme and index (#21)
Browse files Browse the repository at this point in the history
* Adjust spelling in readme and index

* Bump version
  • Loading branch information
LukaszKokot committed Oct 15, 2021
1 parent ef0219c commit 7e7178d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -20,7 +20,7 @@ The package is available on [npm](https://npmjs.org/package/async-wait-until):
$ npm install --save async-wait-until
```

It ships with a [UMD](https://github.com/umdjs/umd) bundle by default (which works well as-is on Node.js and web browsers), but bundles for other module systems are also available in the package's `dist/` folder.
It ships with an [UMD](https://github.com/umdjs/umd) bundle by default (which works well as-is on Node.js and web browsers), but bundles for other module systems are also available in the package's `dist/` folder.

```ts
import { waitUntil } from 'async-wait-until';
Expand Down Expand Up @@ -158,7 +158,7 @@ const doOutThing = async () => {
// Yup! Easy right?
const divNode = await waitUntil(
// Here, we specify a function that will be repeatedly called from time to time
// Let's call this kind of functions a `predicate`
// Let's call this kind of function a `predicate`
() => window.document.body.querySelector('div.spooky-spooky-skeleton'),
// Here, we can specify a timeout in milliseconds. Once it passes,
// we'll stop waiting and throw an exception
Expand All @@ -171,7 +171,7 @@ const doOutThing = async () => {

However, we aren't 100% sure that the `<div />` will be added within 10 seconds. What will happen if 10 seconds have passed and the `<div />` node still isn't there?

From the above code, it's clear that our `'predicate'` function (or simply `'preddcate'`) won't return the DOM node. So what `waitUntil` will do in that case is it will throw a `TimeoutException` (also exported from the library so you can handle it).
From the above code, it's clear that our `'predicate'` function (or simply `'predicate'`) won't return the DOM node. So what `waitUntil` will do in that case is it will throw a `TimeoutException` (also exported from the library so you can handle it).

```js
import { doTheDivThing } from './a-sneaky-module.js';
Expand All @@ -190,10 +190,10 @@ const doOurThing = async () => {
} catch (e) {
if (e instanceof TimeoutError) {
// Unfortunately, 10 seconds have passed but we haven't detected the `<div />`
// If we had a UI, we could show an error there or allow user to retry
// If we had a UI, we could show an error there or allow the user to retry
alert('No <div /> have been detected unfortunately');
} else {
// Some another error, most likely thrown from the predicate function.
// Some other error, most likely thrown from the predicate function.
alert('Unknown error occurred');
console.error(e);
}
Expand All @@ -205,15 +205,15 @@ So, summing up the above, the predicate will run again and again within the give

### API

Lets' start with the `waitUntil` function. It takes up to two parameters (**deprecated**: up to three), and returns a Promise that will be resolved with the first non-falsy value returned by the predicate.
Let's start with the `waitUntil` function. It takes up to two parameters (**deprecated**: up to three), and returns a Promise that will be resolved with the first non-falsy value returned by the predicate.

Parameter | Type | Required | Default | Description
------------ | ------------- | ------------- | ------------- | -------------
`predicate` | Function | ✅ Yes | - | A function that is expected to return a non-falsy (aka a `'truthy'`) value, or a Promise to return such a value. Hence, *both sync and async functions are supported*.
`options` | Options object | 🚫 No | 5000 ms | Options for the wait algorithm implemented by `waitUntil`, see its properties on the below table. **Deprecated**: timeout in milliseconds.
~~intervalBetweenAttempts~~ | number | 🚫 No | 50 ms | **Deprecated parameter**: number of milliseconds between retry attempts. Please use options instead.

Above, you could see the options param. Here are the available **options**:
Above, you can see the options param. Here are the available **options**:

Parameter | Type | Required | Default | Description
------------ | ------------- | ------------- | ------------- | -------------
Expand All @@ -224,7 +224,7 @@ Parameter | Type | Required | Default | Description

#### Waiting for something forever

If you aren't sure how long with a process take, you can use `waitUntil.Forever` (which is a shortcut for [Number.POSITIVE_INFINITY](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)) as the timeout value:
If you aren't sure how long a process will take, you can use `waitUntil.Forever` (which is a shortcut for [Number.POSITIVE_INFINITY](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)) as the timeout value:

```ts
import { waitUntil, WAIT_FOREVER } from 'async-wait-until';
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "async-wait-until",
"version": "2.0.7",
"version": "2.0.8",
"description": "Waits for a given predicate callback to return a truthy value and resolves",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Expand Up @@ -115,7 +115,7 @@ export const WAIT_FOREVER = Number.POSITIVE_INFINITY;
* @param intervalBetweenAttempts *(deprecated)* Interval to wait for between attempts, optional, *50 ms* by default
* @returns A promise to return the given predicate's result, once it resolves with a truthy value
* @template T Result type for the truthy value returned by the predicate
* @throws [[TimeoutError]] An exception throws when the specified timeout interval passes but the predicate doesn't return a truthy value
* @throws [[TimeoutError]] An exception thrown when the specified timeout interval passes but the predicate doesn't return a truthy value
* @throws Error
* @see [[TruthyValue]]
* @see [[FalsyValue]]
Expand Down Expand Up @@ -245,7 +245,7 @@ type ScheduleFn = <T>(callback: (...args: T[]) => void, interval: number) => Sch
*/
type CancelScheduledFn = () => void;
/**
* A stateful abstraction over Node.js & web browser timers, that cancels the scheduled task
* A stateful abstraction over Node.js & web browser timers that cancels the scheduled task
* @private
* @category Common Types
*/
Expand All @@ -256,7 +256,7 @@ type ScheduleCanceler = {
cancel: CancelScheduledFn;
};
/**
* A stateful abstraction over Node.js & web browser timers, that schedules a task
* A stateful abstraction over Node.js & web browser timers that schedules a task
* @private
* @category Common Types
*/
Expand Down

0 comments on commit 7e7178d

Please sign in to comment.