Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Promises basics#3285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
bogdanbacosca wants to merge4 commits intojavascript-tutorial:master
base:master
Choose a base branch
Loading
frombogdanbacosca:promises-basics-en
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions1-js/11-async/02-promise-basics/article.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,15 +214,15 @@ The call `.catch(f)` is a complete analog of `.then(null, f)`, it's just a short

## Cleanup: finally

Just like there's a `finally` clause in a regular `try {...} catch {...}`, there's `finally` in promises.
Just like there's a `finally` clause in a regular `try {...} catch {...}`, there'sa`finally` in promises also.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

maybe:

Just like there's afinally clause in a regulartry {...} catch {...}, there's afinally for promise chains.


The call `.finally(f)` is similar to `.then(f, f)` in the sense that `f` runs always, when the promise is settled: be it resolve or reject.

The idea of `finally` is to set up a handler for performing cleanup/finalizing after the previous operations are complete.

E.g. stopping loading indicators, closing no longer needed connections, etc.

Think of it as a party finisher. No matterwas a party good or bad, how many friends were in it, we still need (or at least should) do a cleanup after it.
Think of it as a party finisher. No matterif a party was good or bad, how many friends were in it, we still need (or at least should) do a cleanup after it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i prefer the solution at#3390


The code may look like this:

Expand DownExpand Up@@ -291,7 +291,7 @@ Sometimes, it might be that a promise is already settled when we add a handler t
In such case, these handlers just run immediately:

```js run
// the promise becomesresolved immediately upon creation
// the promise becomessettled immediately upon creation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

disagree, 'resolve' goes well with use ofresolve in the article's examples. Maybe 'fulfilled' if trying to use ECMA term.

let promise = new Promise(resolve => resolve("done!"));

promise.then(alert); // done! (shows up right now)
Expand DownExpand Up@@ -324,7 +324,7 @@ function loadScript(src, callback) {

Let's rewrite it using Promises.

The new function `loadScript` will not require a callback. Instead, it will create and return a Promise object thatresolves when the loading is complete. The outer code can add handlers (subscribing functions) to it using `.then`:
The new function `loadScript` will not require a callback. Instead, it will create and return a Promise object thatsettles when the loading is complete. The outer code can add handlers (subscribing functions) to it using `.then`:

```js run
function loadScript(src) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp