Skip to content

Commit d4fe53a

Browse files
authored
Merge pull request #357 from mathjax/354
[readme] document Promise API
2 parents 17016a6 + d35e63b commit d4fe53a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ The `start` method start (and restarts) mathjax-node. This allows reconfiguratio
9696

9797
**Note.** This is done automatically when `typeset` is first called (see below).
9898

99-
### `typeset(options, callback)`
99+
### `typeset(options[, callback])`
100100

101-
The `typeset` method is the main method of mathjax-node. It expects a configuration object `input` and a `callback`.
101+
The `typeset` method is the main method of mathjax-node. It expects a configuration object `options` and optionally a callback.
102+
103+
If no `callback` is passed, it will return a Promise.
102104

103105
Once called, `typeset` can be called repeatedly and will optionally store information across calls (see `state` below).
104106

@@ -132,9 +134,9 @@ The following are the default input options.
132134
}
133135
```
134136

135-
### `callback(result, options)`
137+
### `Promise.resolve(result,options)` / `Promise.reject(errors)` / `callback(result, options)`
136138

137-
mathjax-node returns two objects to the `callback`: a `result` object as well as the original input `options`.
139+
mathjax-node returns two objects to `Promise.resolve` or `callback`: a `result` object and the original input `options`.
138140

139141
The `result` object will contain (at most) the following structure:
140142

@@ -165,4 +167,6 @@ The `result` object will contain (at most) the following structure:
165167
}
166168
```
167169

168-
The `options` contains the configuration object passed to `typeset`; this can be useful for passing other data along or for identifying which `typeset()` call is associated with this `callback` call (in case you use the same `callback` function for more than one `typeset()`).
170+
If the `errors` array is non-empty, the Promise will reject, and be passed the `errors` array.
171+
172+
The `options` contains the configuration object passed to `typeset`; this can be useful for passing other data along or for identifying which `typeset()` call is associated with this (`callback`) call (in case you use the same `callback` function for more than one `typeset()`).

0 commit comments

Comments
 (0)