Promises Tutorials
navigator.clipboard API
Reading from and writing to the user's clipboard can be both a very useful and dangerous capability. Used correctly and it's a huge convenience to the user; used dubiously and the user could suffer catastrophic consequences. Imagine a wrong account number or wallet address...
JavaScript Wake Lock API
An enjoyable web apps rely on engineers implementing the APIs that cover all of the small things. Those small things sometimes improve performance, usability, accessibility, and the app's relationship with its host system. The Wake Lock API is the latter -- an API...
navigator.clipboard API
Interacting with a user's host clipboard is something web developers have wanted for both good and evil purposes. On the good side, it's nice to allow users to easily copy text like wallet addresses or branch names; for evil, copying malicious text that the user...
Return a Default Value with Promises Using catch
Last week I tweeted all of you looking for your best JavaScript Array and Promise tricks, and as always, it didn't disappoint -- I learned quite a bit!Today's JavaScript Promise trick is brought to you by Claudio Semeraro: how to use
catch
to...Limit Promise Concurrency with pool
Methods like
Promise.all
,Promise.allSettled
,Promise.race
, and the rest are really excellent for managing multiple Promises, allowing for our apps to embrace async and performance. There are times, however, that limiting the number of concurrent operations may be useful, like rate limiting or simply not wanting...cookieStore: Async Cookie API
One pattern in the JavaScript API world that web development veterans will notice is that we've been creating new methods to accomplish what older, grosser APIs once achieved.
XMLHttpRequest
became thefetch
API, some APIs like Battery became async, and there are dozens of other examples.How to Create an Async Function via “new Function”
One thing I love about JavaScript is that there are many ways to accomplish the same task, one such example being creating functions. There are several patterns for functions; one of the last you see used is the
new Function
method:What if you want...5 Awesome JavaScript Promise Tricks
The Promise API changed the game in JavaScript. We went from abusing
setTimeout
s and settling for synchronous operations to doing everything possible to leverage this new async API. Let's check out a handful of awesome Promise API tricks!Cancel a fetch RequestOne problem we...Promise.allSettled
The Promise object has many useful functions like
all
,resolve
,reject
, andrace
-- stuff we use all the time. One function that many don't know about isPromise.allSettled
, a function that fires when all promises in an array are settled, regardless of whether...How to Cancel a Fetch Request
JavaScript promises have always been a major win for the language -- they've led to a revolution of asynchronous coding that has vastly improved performance on the web. One shortcoming of native promises is that there's no true way to cancel a
fetch
...until now. A...