def METHOD_NAME(promises: List['Promise[S]']) -> 'Promise[List[S]]':
    """
    Takes a list of promises and returns a Promise that gets resolved when all promises
    gets resolved.
    :param      promises: The list of promises
    :returns:   A promise that gets resolved when all passed promises gets resolved.
                Gets passed a list with all resolved values.
    """
    def executor(resolve: ResolveFunc[List[S]]) -> None:
        was_resolved = False
        def recheck_resolve_status(_: S) -> None:
            nonlocal was_resolved
            # We're being called from a Promise that is holding a lock so don't try to use
            # any methods that would try to acquire it.
            if not was_resolved and METHOD_NAME(p.resolved for p in promises):
                was_resolved = True
                values = [p.value for p in promises]
                resolve(values)
        for p in promises:
            assert isinstance(p, Promise)
            p.then(recheck_resolve_status)
    if promises:
        return Promise(executor)
    return Promise.resolve([])