* Returns a transient, read-only hat map for use during the course of a * single command. * * Please do not hold onto this copy beyond the lifetime of a single command, * because it will get stale. * @param usePrePhraseSnapshot Whether to use pre-phrase snapshot * @returns A readab
(usePrePhraseSnapshot: boolean)
| 82 | * @returns A readable snapshot of the map |
| 83 | */ |
| 84 | async getReadableMap(usePrePhraseSnapshot: boolean): Promise<ReadOnlyHatMap> { |
| 85 | // NB: Take a snapshot before we return the map if it is the beginning of |
| 86 | // the phrase so all commands will get the same map over the course of the |
| 87 | // phrase |
| 88 | await this.maybeTakePrePhraseSnapshot(); |
| 89 | |
| 90 | if (usePrePhraseSnapshot) { |
| 91 | if (this.lastSignalVersion == null) { |
| 92 | console.error( |
| 93 | "Pre phrase snapshot requested but no signal was present; please upgrade command client" |
| 94 | ); |
| 95 | return this.activeMap; |
| 96 | } |
| 97 | |
| 98 | if (this.prePhraseMapSnapshot == null) { |
| 99 | console.error( |
| 100 | "Navigation map pre-phrase snapshot requested, but no snapshot has been taken" |
| 101 | ); |
| 102 | return this.activeMap; |
| 103 | } |
| 104 | |
| 105 | if ( |
| 106 | abs(hrtime.bigint() - this.prePhraseMapsSnapshotTimestamp!) > |
| 107 | PRE_PHRASE_SNAPSHOT_MAX_AGE_NS |
| 108 | ) { |
| 109 | console.error( |
| 110 | "Navigation map pre-phrase snapshot requested, but snapshot is more than a minute old" |
| 111 | ); |
| 112 | return this.activeMap; |
| 113 | } |
| 114 | |
| 115 | return this.prePhraseMapSnapshot; |
| 116 | } |
| 117 | |
| 118 | return this.activeMap; |
| 119 | } |
| 120 | |
| 121 | public dispose() { |
| 122 | this.activeMap.dispose(); |