Closed ttoohey closed 1 year ago
Invoking the return
method of an iterator should finish it immediately. Except for wrong iterator implementations - I don't think there are cases where you need to flush pending messages after completing it.
return(value)
A function that accepts zero or one argument and returns an object conforming to theIteratorResult
interface, typically withvalue
equal to thevalue
passed in anddone
equal totrue
. Calling this method tells the iterator that the caller does not intend to make any morenext()
calls and can perform any cleanup actions.
Having read the return
method definition on MDN, we can notice 2 things about it:
done
should be true
next()
shouldn't be called after return()
allow subscriptions to have a cleanup phase after calling
.return()
and ensure the iterator is 'done' before finishing