setTimeout(function, delay)docs: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
I've always thought that setTimeout would call the function when the delay was up,
maybe a little later,
but never before.
| const { PassThrough, finished } = require('stream'); | |
| console.log('Waiting for stream to finish...'); | |
| finished(new PassThrough(), (err) => { | |
| // This callback is never called and the process exits with exit code 0 right away | |
| console.log('Stream has finished!', { err }); | |
| }); |
| 'use strict' | |
| const { Worker } = require('worker_threads') | |
| const worker = new Worker(` | |
| const { workerData, parentPort } = require('worker_threads') | |
| const result = workerData.str.match(workerData.regex) | |
| parentPort.postMessage(result) | |
| `, { | |
| workerData: { |
| 'use strict' | |
| const asyncHooks = require('async_hooks') | |
| const asyncIds = new Set() | |
| const asyncHook = asyncHooks.createHook({ | |
| init (asyncId, type, triggerAsyncId, resource) { | |
| const eid = asyncHooks.executionAsyncId() | |
| process._rawDebug(`${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${eid}`, resource) |
| 'use strict' | |
| const { Writable } = require('readable-stream') | |
| let stream | |
| console.log('write') | |
| stream = getStream() | |
| stream.write('foo') |
| 'use strict' | |
| const zlib = require('zlib') | |
| const http = require('http') | |
| const body = zlib.gzipSync(JSON.stringify({ | |
| errors: { | |
| ERR_QUEUE_FULL: { | |
| count: 23, | |
| message: 'queue is full' |
| 'use strict' | |
| const http = require('http') | |
| const server = http.createServer(function (req, res) { | |
| console.log(req.method, req.url) | |
| res.socket.end() // Half-close the socket by sending FIN packet | |
| }) | |
| server.listen(8200, function () { |
setTimeout(function, delay)docs: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
I've always thought that setTimeout would call the function when the delay was up,
maybe a little later,
but never before.
| var assert = require('assert') | |
| var events = require('events') | |
| assert(events.usingDomains) |
| Write-Host "Preparing to download and install Elasticsearch..." -ForegroundColor Cyan | |
| $esVersion = "6.1.2" | |
| $downloadUrl = "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$($esVersion).zip" | |
| $zipPath = "$($env:USERPROFILE)\elasticsearch-$esVersion.zip" | |
| $extractRoot = "$env:SYSTEMDRIVE\Elasticsearch" | |
| $esRoot = "$extractRoot\elasticsearch-$esVersion" | |
| Write-Host "Downloading Elasticsearch..." | |
| (New-Object Net.WebClient).DownloadFile($downloadUrl, $zipPath) | |
| 7z x $zipPath -y -o"$extractRoot" | Out-Null |
| Write-Host "Downloading Redis..." -ForegroundColor Cyan | |
| $redisRoot = "$env:SYSTEMDRIVE\Redis" | |
| $zipPath = "$($env:USERPROFILE)\redis-2.8.19.zip" | |
| (New-Object Net.WebClient).DownloadFile('https://github.com/MSOpenTech/redis/releases/download/win-2.8.19/redis-2.8.19.zip', $zipPath) | |
| 7z x $zipPath -y -o"$redisRoot" | Out-Null | |
| del $zipPath | |
| Write-Host "Installing Redis as a Windows service..." | |
| & "$redisRoot\redis-server.exe" --service-install |