import { _try } from "https://deno.land/x/ayonli_jsext@v0.9.72/workerd/index.ts";
Invokes an async generator function and renders its yield value and result in
an [err, val]
tuple.
Examples
Example 1
Example 1
import _try from "@ayonli/jsext/try";
const iter = _try(async function* () {
// do something that may fail
});
for await (const [err, val] of iter) {
if (err) {
console.error("something went wrong:", err);
} else {
console.log("current value:", val);
}
}
Invokes a generator function and renders its yield value and result in an
[err, val]
tuple.
Examples
Example 1
Example 1
import _try from "@ayonli/jsext/try";
const iter = _try(function* () {
// do something that may fail
});
for (const [err, val] of iter) {
if (err) {
console.error("something went wrong:", err);
} else {
console.log("current value:", val);
}
}
Invokes an async function and renders its result in an [err, res]
tuple.
Examples
Example 1
Example 1
import _try from "@ayonli/jsext/try";
import axios from "axios";
let [err, res] = await _try(async () => {
return await axios.get("https://example.org");
});
if (err) {
res = (err as any)["response"];
}
Invokes a function and renders its result in an [err, res]
tuple.
Examples
Example 1
Example 1
import _try from "@ayonli/jsext/try";
const [err, res] = _try(() => {
// do something that may fail
});
Resolves an async generator and renders its yield value and result in an
[err, val]
tuple.
Examples
Example 1
Example 1
import _try from "@ayonli/jsext/try";
async function* gen() {
// do something that may fail
}
for await (const [err, val] of _try(gen())) {
if (err) {
console.error("something went wrong:", err);
} else {
console.log("current value:", val);
}
}
Resolves a generator and renders its yield value and result in an [err, val]
tuple.
Examples
Example 1
Example 1
import _try from "@ayonli/jsext/try";
import { range } from "@ayonli/jsext/number";
const iter = range(1, 10);
for (const [err, val] of _try(iter)) {
if (err) {
console.error("something went wrong:", err);
} else {
console.log("current value:", val);
}
}
Resolves a promise and renders its result in an [err, res]
tuple.
Examples
Example 1
Example 1
import _try from "@ayonli/jsext/try";
import axios from "axios";
let [err, res] = await _try(axios.get("https://example.org"));
if (err) {
res = (err as any)["response"];
}
Parameters
job: PromiseLike<R>