minor tweak to promises + docs...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-04-07 03:17:02 +03:00
parent 13c8dce517
commit 99eabf49a8
3 changed files with 19 additions and 4 deletions

View File

@ -258,6 +258,17 @@ object.Constructor('InteractivePromise', Promise, {
__new__: function(_, handler){
var handlers = []
var onmessage = function(func){
var h = obj == null ?
// NOTE: we need to get the handlers from .__message_handlers
// unless we are not fully defined yet, then use the
// bootstrap container (handlers)...
// ...since we can call onmessage(..) while the promise
// is still defined there is no way to .send(..) until it
// returns a promise object, this races here are highly
// unlikely...
handlers
: (obj.__message_handlers =
obj.__message_handlers ?? [])
handlers.push(func) }
var obj = Reflect.construct(
@ -267,7 +278,6 @@ object.Constructor('InteractivePromise', Promise, {
: [function(resolve, reject){
return handler(resolve, reject, onmessage) }],
InteractivePromise)
Object.defineProperty(obj, '__message_handlers', {
value: handlers,
enumerable: false,

View File

@ -1173,7 +1173,7 @@ printer
```
Note that message handling is independent of promise state, so in the above case
we can still _flush_ the buffer even if the promise is resolved
we can still populate the buffer and _flush_ it even if the promise is resolved
```javascript
printer
.send('log', 'some other message...')
@ -1183,6 +1183,11 @@ printer
If the user wants to reject messages after the promise is finalized it is their
responsibility.
<!--
XXX to clear buffers just delete/empty the .__message_handlers...
...not sure if this should be either tooled or documented...
-->
#### `Promise.interactive(..)`
@ -1214,7 +1219,7 @@ Send a message to an interactive promise
```
Sending a message triggers message handlers registered via `<onmessage>(..)`
passing each handler the sent arguments.
passing each handler the arguments.

View File

@ -1,6 +1,6 @@
{
"name": "ig-types",
"version": "6.0.10",
"version": "6.0.11",
"description": "Generic JavaScript types and type extensions...",
"main": "main.js",
"scripts": {