> For the complete documentation index, see [llms.txt](https://docs.yemreak.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yemreak.com/arsiv/programming/promiseleri-calistirmadan-tanimlamak-icin-function-olarak-tanimlanmali.md).

# Promise’leri calistirmadan tanimlamak icin function () ⇒ {} olarak tanimlanmali

programming, typescript, javascript, promise, async-await, promise, function calling

Bu fonksiyon tanımlandığı gibi hemen çalıştırılır. Bu, `prettifyLogs({ exchange, logFile })` işlevinin tanımlandığı gibi çağrılması anlamına gelir. İşlev içindeki Promise'ler map fonksiyonu aracılığıyla bir diziye dönüştürülür ve bu dizi `await Promise.all(promises)` aracılığıyla çalıştırılır. Bu, tüm Promise'lerin tamamlanmasını bekler. Bu nedenle, bu kodu çalıştırdığınızda, tüm log dosyalarının işlenmesi ve düzenlenmesi işlemi otomatik olarak gerçekleşir.

```javascript
async function prettifyLogs({ exchange, logFile }) {
	const outdir = `./logs/${exchange}/${logFile}`
	const infile = `logs/${exchange}/${logFile}.log`
	const logLevels = ["debug", "info", "warn", "error"]

	mkdirSync(outdir, { recursive: true })

	const promises = logLevels.map(async logLevel => {
		const outfile = `${outdir}/${logLevel}.log`
		const command = `./node_modules/.bin/pino-pretty -i pid,hostname -L ${logLevel} < ${infile} > ${outfile}`

		await execPromise(command)
		await execPromise(`split -b 12M -d ${outfile} ${outfile}`)
		unlinkSync(outfile)
	})

	await Promise.all(promises)
	readdirSync(outdir).forEach(file => {
		console.log(`"${outdir}/${file}"`)
	})
}
```

Bu kod parçası, `prettifyLogs({ exchange, logFile })` işlevini bir Promise içine sarar. `prettifyLogsPromise` fonksiyonu çağrıldığında, Promise başlatılır ve işlev çalıştırılır. Bu, isteğe bağlı olarak Promise'leri başlatmanızı sağlar ve onları yalnızca ihtiyaç duyduğunuzda çalıştırabilirsiniz. Bu durum, kodunuzun belirli bir süre boyunca veya belirli koşullar altında bekletilmesi gerektiğinde özellikle kullanışlıdır.

```typescript
const prettifyLogsPromise = 
	async () => await prettifyLogs({ exchange, logFile: promptedLogFile })
```

Bu yaklaşım, Promise'lerin tanımlanmasını ve çalıştırılmasını kontrol altına almak için bir yol sağlar. Bu, özellikle büyük veri setleriyle çalışırken ve/veya ağ istekleri yaparken yararlıdır, çünkü bu durumlarda işlemlerin tamamlanması genellikle zaman alır. Promise'leri erkenden başlatmak, uygulamanızın performansını olumsız etkileyebilir. Bu nedenle, bu tür durumlar için Promise'leri tanımlama ve yalnızca ihtiyaç duyduğunuzda başlatma yeteneği, kodunuzun daha esnek ve verimli olmasını sağlar.

```typescript
await Promise.all(prettifyLogsPromise())
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.yemreak.com/arsiv/programming/promiseleri-calistirmadan-tanimlamak-icin-function-olarak-tanimlanmali.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
