diff --git a/index.bs b/index.bs index 0e955244..e112cb1d 100644 --- a/index.bs +++ b/index.bs @@ -1080,10 +1080,16 @@ Reads back the {{MLTensor/[[data]]}} of an {{MLTensor}} from the {{MLContext}}.{ 1. If |tensor|.{{MLTensor/[[isDestroyed]]}} is true, then return [=a new promise=] [=rejected=] with a {{TypeError}}. 1. If |tensor|.{{MLTensor/[[descriptor]]}}.{{MLTensorDescriptor/readable}} is false, then return [=a new promise=] [=rejected=] with a {{TypeError}}. 1. Let |promise| be [=a new promise=]. + 1. [=set/Append=] |promise| to |tensor|.{{MLTensor/[[pendingPromises]]}}. 1. Enqueue the following steps to |tensor|.{{MLGraph/[[context]]}}.{{MLContext/[[timeline]]}}: 1. Let |bytes| be a [=/byte sequence=] containing a copy of |tensor|.{{MLTensor/[[data]]}}. - 1. If that fails, then [=queue an ML task=] with |global| to [=reject=] |promise| with an "{{UnknownError}}" {{DOMException}}, and abort these steps. - 1. Otherwise, [=queue an ML task=] with |global| to [=ArrayBuffer/create=] an {{ArrayBuffer}} |result| given |bytes| and |realm| and then [=resolve=] |promise| with |result|. + 1. If that fails, then [=queue an ML task=] with |global| and the following steps: + 1. [=set/Remove=] |promise| from |tensor|.{{MLTensor/[[pendingPromises]]}}. + 1. [=Reject=] |promise| with an "{{UnknownError}}" {{DOMException}}. + 1. Otherwise, [=queue an ML task=] with |global| and the following steps: + 1. [=set/Remove=] |promise| from |tensor|.{{MLTensor/[[pendingPromises]]}}. + 1. Let |buffer| be the result of [=ArrayBuffer/creating=] an {{ArrayBuffer}} from |bytes| in |realm|. + 1. [=Resolve=] |promise| with |buffer|. 1. Return |promise|. @@ -1109,10 +1115,14 @@ Bring-your-own-buffer variant of {{MLContext/readTensor(tensor)}}. Reads back th 1. If |tensor|.{{MLTensor/[[descriptor]]}}.{{MLTensorDescriptor/readable}} is false, then return [=a new promise=] [=rejected=] with a {{TypeError}}. 1. If [=validating buffer with descriptor=] given |outputData| and |tensor|.{{MLTensor/[[descriptor]]}} returns false, then return [=a new promise=] [=rejected=] with a {{TypeError}}. 1. Let |promise| be [=a new promise=]. + 1. [=set/Append=] |promise| to |tensor|.{{MLTensor/[[pendingPromises]]}}. 1. Enqueue the following steps to |tensor|.{{MLGraph/[[context]]}}.{{MLContext/[[timeline]]}}: 1. Let |bytes| be a [=/byte sequence=] containing a copy of |tensor|.{{MLTensor/[[data]]}}. - 1. If that fails, then [=queue an ML task=] with |global| to [=reject=] |promise| with an "{{UnknownError}}" {{DOMException}}, and abort these steps. + 1. If that fails, then [=queue an ML task=] with |global| and the following steps: + 1. [=set/Remove=] |promise| from |tensor|.{{MLTensor/[[pendingPromises]]}}. + 1. [=Reject=] |promise| with an "{{UnknownError}}" {{DOMException}}. 1. Otherwise, [=queue an ML task=] with |global| and the following steps: + 1. [=set/Remove=] |promise| from |tensor|.{{MLTensor/[[pendingPromises]]}}. 1. If |outputData| is [=BufferSource/detached=], [=reject=] |promise| with a {{TypeError}}, and abort these steps. Note: [=Validating buffer with descriptor=] above will fail if |outputData| is detached, but it is possible that |outputData| could be detached between that step and this one. @@ -1478,6 +1488,10 @@ interface MLTensor { :: The {{MLTensor}}'s descriptor. + : \[[pendingPromises]] of type [=/set=] of {{Promise}}s + :: + Promises corresponding to {{MLContext}}.{{MLContext/readTensor(tensor)}} method calls which are in-progress and have yet to resolve. All pending promises will be rejected when the {{MLTensor}} is destroyed. + : \[[isDestroyed]] of type {{boolean}} :: Whether {{MLTensor}}.{{MLTensor/destroy()}} has been called. Once destroyed, the {{MLTensor}} can no longer be used. @@ -1528,6 +1542,9 @@ Releases the resources associated with the {{MLTensor}}. This method is idempote The destroy() method steps are: 1. Set [=this=].{{MLTensor/[[isDestroyed]]}} to true. + 1. [=set/For each=] |promise| in [=this=].{{MLTensor/[[pendingPromises]]}}: + 1. [=set/Remove=] |promise| from [=this=].{{MLTensor/[[pendingPromises]]}}. + 1. [=Reject=] |promise| with an "{{InvalidStateError}}" {{DOMException}}. 1. Enqueue the following steps to [=this=].{{MLTensor/[[context]]}}.{{MLContext/[[timeline]]}}: 1. Release [=this=].{{MLTensor/[[data]]}}. 1. Return {{undefined}}.