* Returns the promise that's resolved when the signal is triggered. The * resolved value is the time of the signal. * @param {string} name * @return {Promise }
(name)
| 50 | * @return {Promise<TimestampDef>} |
| 51 | */ |
| 52 | whenSignal(name) { |
| 53 | let promiseStruct = this.promiseMap_?.[name]; |
| 54 | if (!promiseStruct) { |
| 55 | const result = this.map_[name]; |
| 56 | if (result != null) { |
| 57 | // Immediately resolve signal. |
| 58 | const promise = |
| 59 | typeof result == 'number' |
| 60 | ? Promise.resolve(result) |
| 61 | : Promise.reject(result); |
| 62 | promiseStruct = {promise}; |
| 63 | } else { |
| 64 | // Allocate the promise/resolver for when the signal arrives in the |
| 65 | // future. |
| 66 | promiseStruct = new Deferred(); |
| 67 | } |
| 68 | if (!this.promiseMap_) { |
| 69 | this.promiseMap_ = map(); |
| 70 | } |
| 71 | this.promiseMap_[name] = promiseStruct; |
| 72 | } |
| 73 | return promiseStruct.promise; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Triggers the signal with the specified name on the element. The time is |
no test coverage detected