On Tue, Jun 9, 2015 at 11:11 AM, Mark S. Miller <erig...@google.com> wrote:
> Ok, thanks for the example. I understand your rationale. This is what I > asked for but not what I was really looking for. Can we come up with an > example where class and species usefully differ where neither is Promise? > IOW, where the species a proper subclass of Promise and a proper superclass > of the class in question. > http://www.mimuw.edu.pl/~sl/teaching/00_01/Delfin_EC/Glossary.htm#S says: > species: The generic class of an object. This is normally the same as the class of an object, otherwise it is a class which describes the generic > group of classes to which a particular class belongs. Note that this does not necessarily have to be class from the same branch of the hierarchy. But I was not able to find this any examples where the species was not "from the same branch of the hierachy" in my smalltalk research. The only examples I could dig up had the species equal to the top-level superclass for the "generic group", like Array, Promise, etc. But I'm not a smalltalk expert, by any means. I hope that some of the smalltalkers among us (or those who work with former smalltalkers?) might be able to come up with more examples. That said, I think the WeakPromise and TimeoutPromise examples are reasonably compelling. Further, note that if you are using the `prfun` library, the "Promise" you are using is actually a subclass of `globals.Promise`. This is so that `prfun` can add all of its fun `Promise.try` etc methods without polluting the global `Promise`. So in that case: `PrFunPromise extends Promise`, `TimeoutPromise extends PrFunPromise`, and `TimeoutPromise[Symbol.species] = PrFunPromise`. But that's probably not really what you were looking for, either. On Tue, Jun 9, 2015 at 11:04 AM, Allen Wirfs-Brock <al...@wirfs-brock.com> wrote: > I generally agree. You invoke one of these methods on a specific Promise > constructor, presumably with the intend that it is an instance to that > constructor you expect to get back. > > For example, compare the likely intent of: > WeakPromise.all(iterator) > and > Promise.all(iterator) > > It seems just like what we discussed for Promise.resolve > I generally agree, and would not object to travelling down this path. *However*, note that the implementations given for `Promise.all` and `Promise.race` use Promises in two different ways: (1) every element of the array argument has `C1.resolve(elem).then(....)` applied to it, and (2) the result is constructed with `NewPromiseCapability(C2)`. It's not entirely clear to me that C1 and C2 should be the same. Consider the `TimeoutPromise`: do we want to apply a timeout to every element individually *and* to the result as a whole? It seems that C1 might use species (to avoid the timeout/weak reference), but C2 ignore it (to apply the timeout/weak reference to the final result) The idea that `WeakPromise.all(x)` means `WeakPromise.resolve(x).all()` is a little bit surprising (because the constructed `WeakPromise` is not visible externally and thus the result honors species and is not itself a `WeakPromise`), but does have a consistency of its own. So I'm torn. But if we decided that `WeakPromise.all()` should return a `WeakPromise` then I'd suggest that we change step 6 from: > Let promiseCapability be NewPromiseCapability(C). to > Let promiseCapability be NewPromiseCapability(this). in both `Promise.all` and `Promise.race`, but leave the definition of C otherwise alone, so that internally-created promises honor the species. --scott
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss