Documentation: Clarify when promise body gets executed

This commit is contained in:
Johannes Fahrenkrug 2019-11-15 11:57:38 -05:00
parent 8fbf6985b4
commit 5e2e7e3a75
No known key found for this signature in database
GPG Key ID: 31052A52D4CAA081

View File

@ -258,7 +258,7 @@ You want `recover`.
Often people are confused about when Promises “start”. Is it immediately? Is it
later? Is it when you call `then`?
The answer is: The promise **body** executes right after the promise is created, on the current thread.
The answer is: The promise **body** executes during initialization of the promise, on the current thread.
As an example, `"Executing the promise body"` will be printed to the console right after the promise is created,
without having to call `then` on the promise.
@ -282,7 +282,7 @@ let testPromise = Promise<Bool> { seal in
}
```
The message `Executing the promise body.` is being logged right away, but the message `Executing asyncAfter.`
The message `"Executing the promise body."` is being logged right away, but the message `"Executing asyncAfter."`
is only logged three seconds later. In this case `DispatchQueue` is responsible for deciding when to execute
the task you pass to it, PromiseKit has nothing to do with it.