Although different people use different terms, in the general terminology “to fulfill” means to make a promise in a “successful” state (as opposed to a “rejection”) - a state in which then handlers will be launched that hang it.
In other words, you cannot “fulfill” a promise with a promise. You can execute it with a value. (By the way, the term "permission" usually means either fulfillment or rejection.)
What you can do is return the promise from the .then handler, and this will entail replacing the original promise with the returned promise.
Here is a simple example:
asyncTask1 . then(asyncTask2) . then(processData)
where asyncTask1 is the promise, and asyncTask2 is the function that returns the promise. Therefore, when asyncTask1 is executed (successful), asyncTask2 is asyncTask2 , and the promise returned by .then is “canceled” by the promise of asyncTask2 , so that when it ends, the data can be processed.
I can do something like this by calling Promise.resolve with a promise as a parameter. This is a little wrong, because I do not allow the promise in a technical sense. Instead, a new promise has appeared that is “populated” with the promise I made. This is also useless because using the result is just like using the promise I made:
Promise.resolve(asyncTask2)
behaves exactly like
asyncTask2
(Assuming that asyncTask2 is already a promise, otherwise Promise.resolve has the effect of creating a promise that immediately executes with the passed value.)
Just as you can make a promise to Promise.resolve , you can pass the promise to the resolve function, provided to you as a callback parameter of the promise constructor. If the parameter you pass to resolve does not promise, the promise immediately matches that value. However, if the parameter that you switch to resolve is another promise, that promise takes over the body of the promise you are building. In other words, the promise you are building begins to behave exactly the same as the promise passed to resolve .
By "behave exactly" I mean that if the promise that you pass to resolve is already fulfilled, the promise that you build instantly fulfills the same value. If the promise you pass to resolve is already rejected, the promise you are building is immediately rejected for the same reason. If the promise that you pass to resolve is not yet resolved, then any then handlers will be processed with which you hang the promise that you build if and when the promise that you pass to resolve resolved.
Just as it is confusing that Promise.resolve can lead to a promise that is not actually resolved, it is also confusing that calling the resolve function passed to you as a parameter to the promise constructor may not actually allow the construction of the promise. if you call it an unresolved promise. Instead, as I said a couple of times, this leads to the fact that the promise is built in a state of complete congruence with the promise passed to resolve .
Therefore, if I miss the point of your question, the pickfile can be written as
function pickFile() { return new Promise(function(resolve, reject) { ...display the file picker...
I didn’t understand your question very clearly, so this may not be what you want. Please clarify if you want.