| 1134 | // change event and sometimes this can be too early and get an empty buffer. |
| 1135 | // Poll until the file's modified time has changed before reading again. |
| 1136 | async function readModifiedFile(file: string): Promise<string> { |
| 1137 | const content = await fsp.readFile(file, 'utf-8') |
| 1138 | if (!content) { |
| 1139 | const mtime = (await fsp.stat(file)).mtimeMs |
| 1140 | |
| 1141 | for (let n = 0; n < 10; n++) { |
| 1142 | await new Promise((r) => setTimeout(r, 10)) |
| 1143 | const newMtime = (await fsp.stat(file)).mtimeMs |
| 1144 | if (newMtime !== mtime) { |
| 1145 | break |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | return await fsp.readFile(file, 'utf-8') |
| 1150 | } else { |
| 1151 | return content |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | export type ServerHotChannelApi = { |
| 1156 | innerEmitter: EventEmitter |