Stage 0 Draft / October 2, 2020

Promise.delay and Promise.timeout

1 Promise Objects

1.1 Properties of the Promise Constructor

1.1.1 Promise.delay ( afterTime )

  1. Let C be the this value.
  2. Let promiseCapability be ? NewPromiseCapability(C).
  3. Let promise be promiseCapability.[[Promise]].
  4. Let job be a new Job Abstract Closure with no parameters that captures promiseCapability, and then and performs the following steps when called:
    1. Return Call(promiseCapability.[[Resolve]], undefined, «»).
  5. IfAbruptRejectPromise(HostEnqueuePromiseJob(job.[[Job]], job.[[Realm]], afterTime), promise).
  6. Return promise.

1.1.2 Promise.timeout ( wrapPromise, afterTime )

  1. Let C be the this value.
  2. Let promiseCapability be ? NewPromiseCapability(C).
  3. Let promise be promiseCapability.[[Promise]].
  4. Let job be a new Job Abstract Closure with no parameters that captures promiseCapability, and then and performs the following steps when called:
    1. Return Call(promiseCapability.[[Reject]], undefined, «»).
  5. IfAbruptRejectPromise(HostEnqueuePromiseJob(job.[[Job]], job.[[Realm]], afterTime), promise).
  6. IfAbruptRejectPromise(Invoke(wrapPromise, "then", «promise.[[Resolve]], promise.[[Reject]]»), promise).
  7. Return promise.

2 Jobs and Host Operations to Enqueue Jobs

2.1 HostEnqueuePromiseJob ( job, realm, [afterTime] )

HostEnqueuePromiseJob is a host-defined abstract operation that schedules the Job Abstract Closure job to be performed, at some future time, with optional minimal future time requirement afterTime. The Abstract Closures used with this algorithm are intended to be related to the handling of Promises, or otherwise, to be scheduled with equal priority to Promise handling operations.

The realm parameter is either null or a Realm Record.

The implementation of HostEnqueuePromiseJob must conform to the requirements in Jobs as well as the following:

  • If realm is not null, each time job is invoked the implementation must perform implementation-defined steps such that execution is prepared to evaluate ECMAScript code at the time of job's invocation.
  • Let scriptOrModule be GetActiveScriptOrModule() at the time HostEnqueuePromiseJob is invoked. If realm is not null, each time job is invoked the implementation must perform implementation-defined steps such that scriptOrModule is the active script or module at the time of job's invocation.
  • Jobs must run in the same order as the HostEnqueuePromiseJob invocations that scheduled them.
  • If afterTime presents, job must not be executed before the time that afterTime describes.
Note
The interpretation of afterTime is depending on the host. The host can return AbruptCompletion if the environment does not allow clock-dependent behaviors or afterTime is an invalid value.

A Copyright & Software License

Copyright Notice

© 2020 Jack Works

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.