Gathering detailed insights and metrics for @solid-primitives/promise
Gathering detailed insights and metrics for @solid-primitives/promise
Gathering detailed insights and metrics for @solid-primitives/promise
Gathering detailed insights and metrics for @solid-primitives/promise
A library of high-quality primitives that extend SolidJS reactivity.
npm install @solid-primitives/promise
Typescript
Module System
Node Version
NPM Version
@solid-primitives/utils@6.3.1
Updated on Apr 27, 2025
@solid-primitives/workers@0.4.1
Updated on Apr 27, 2025
@solid-primitives/websocket@1.3.1
Updated on Apr 27, 2025
@solid-primitives/virtual@0.2.1
Updated on Apr 27, 2025
@solid-primitives/upload@0.1.1
Updated on Apr 27, 2025
@solid-primitives/styles@0.1.1
Updated on Apr 27, 2025
TypeScript (98.3%)
SCSS (0.73%)
JavaScript (0.64%)
HTML (0.21%)
CSS (0.09%)
Rust (0.02%)
Total Downloads
53,280
Last Day
217
Last Week
1,137
Last Month
4,376
Last Year
49,744
MIT License
1,374 Stars
3,770 Commits
138 Forks
10 Watchers
25 Branches
94 Contributors
Updated on May 09, 2025
Latest Version
1.1.1
Package Id
@solid-primitives/promise@1.1.1
Unpacked Size
12.27 kB
Size
4.06 kB
File Count
5
NPM Version
10.8.2
Node Version
20.19.0
Published on
Apr 27, 2025
Cumulative downloads
Total Downloads
Last Day
-14.2%
217
Compared to previous day
Last Week
-11.1%
1,137
Compared to previous week
Last Month
-7.7%
4,376
Compared to previous month
Last Year
2,046.9%
49,744
Compared to previous year
A library of reactive primitives and helpers for handling promises.
promiseTimeout
— Creates a promise that resolves (or rejects) after given time.raceTimeout
— Combination of Promise.race()
and promiseTimeout
.until
— Promised one-time watch for changes. Await a reactive condition.1npm install @solid-primitives/promise 2# or 3yarn add @solid-primitives/promise
promiseTimeout
Creates a promise that resolves (or rejects) after given time.
1import { promiseTimeout } from "@solid-primitives/promise"; 2 3await promiseTimeout(1000); // resolves after 1 second 4 5try { 6 await promiseTimeout(1000, true, "timeout"); // rejects with 'timeout' after 1 second 7} catch (e) { 8 console.log(e); // 'timeout' 9}
raceTimeout
Combination of Promise.race()
and promiseTimeout
.
1import { raceTimeout } from "@solid-primitives/promise"; 2 3await raceTimeout(myPromise, 1000); // resolves after 1 second, or when "myPromise" resolves 4 5try { 6 await raceTimeout(myPromise, 1000, true, "timeout"); // rejects with 'timeout' after 1 second, or resolves when "myPromise" resolves 7} catch (e) { 8 console.log(e); // 'timeout' 9}
until
Promised one-time watch for changes. Await a reactive condition.
It takes a signal or a reactive condition — which will resolve the promise if truthy — as an argument.
Returns a promise that resolves a truthy value of a condition. Or rejects when it's root get's disposed.
no need for createMemo, it's memoized internally
1import { until } from "@solid-primitives/promise"; 2 3const [count, setCount] = createSignal(0); 4 5await until(() => count() > 5);
createResource
It also can be used as a source for createResource
.
1import { until } from "@solid-primitives/promise"; 2 3const [state, setState] = createSignal(null); 4 5const [data] = createResource(() => until(state));
raceTimeout
To limit the maximum time it has for resolving
1import { until, raceTimeout } from "@solid-primitives/promise"; 2 3try { 4 const result = await raceTimeout(until(condition), 2000, true, "until was too slow"); 5 // if until is quicker: 6 result; // => truthy condition value 7} catch (err) { 8 // if timeouts: 9 console.log(err); // => "until was too slow" 10}
If you don't want to use raceTimeout
, there are other ways to stop the reactive computation of until
if needed.
First, it will stop itself "onCleanup".
1// the same goes for components as they are roots too
2createRoot(dispose => {
3
4 // disposing root causes the promise to reject,
5 // so you need to catch that outcome to prevent errors
6 until(condition)
7 .then(res => {...})
8 .catch(() => {})
9
10 dispose()
11})
Second, using the .dispose()
method.
1// until returns a promise with a dispose method in it 2const promise = until(condition); 3 4// you need to catch the rejection here too 5promise.then().catch(); 6 7promise.dispose();
until
+ createResource
demo: https://codesandbox.io/s/until-resource-demo-sfs7c?file=/src/index.tsx
until
as createResource
fetcher: https://codesandbox.io/s/until-as-resource-fetcher-6sl0e?file=/src/index.tsx
See CHANGELOG.md
Original idea for this primitive comes from a VueUse's function of the same name.
No vulnerabilities found.
No security vulnerabilities found.