What
The value in promise is permitted to mutate at most once.
-
Created:
Pending: Empty box that contains nothing
-
Eventually:
Resolved: like putting something inside the box.Rejected: box filled with an Exception- Contents may never change after resolved or rejected
-
The client code that wants to make use of concurrency will need to access promises:
resolvedorpending, and make use of the resolved values. -
The library and OS code that implements concurrency will need to mutate the promise, to actually
resolveorrejectit. Client code does not need to mutate the promise.
Abstraction Layer resolver
- Create a new promise and its associated resolver. The promise is pending.
- Call an OS function that will concurrently read the string, then invoke the resolver on that string.
- Return the promise (but not resolver) to the client. The OS meanwhile continues to work on reading the string.