这个问题通常是因为程序调用了write()
或writeAll()
方法后,需要调用flush()
函数来刷新缓冲区并将数据写入控制台。以下是一个简单的示例:
import { BufWriter } from "https://deno.land/std/io/bufio.ts";
import { stdout } from "https://deno.land/std/io/mod.ts";
const encoder = new TextEncoder();
const writer = new BufWriter(stdout);
const message = "Hello world!";
await writer.write(encoder.encode(message));
await writer.flush();
注意,即使使用异步的BufWriterAsync
,也需要在调用write()
方法之后调用flush()
函数。
import { BufWriterAsync } from "https://deno.land/std/io/bufio.ts";
import { stdout } from "https://deno.land/std/io/mod.ts";
const encoder = new TextEncoder();
const writer = new BufWriterAsync(stdout);
const message = "Hello world!";
await writer.write(encoder.encode(message));
await writer.flush();
通过这种方式使用BufWriterAsync
对象时,也需要使用await
来等待flush()
函数完成。