finally

Bun

Symbol

$.ShellPromise.finally

finally(onfinally?: null | () => void): Promise<ShellOutput>

Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

@param onfinally

The callback to execute when the Promise is settled (fulfilled or rejected).

@returns

A Promise for the completion of the callback.

Referenced types

interface ShellOutput

  • readonly exitCode: number
  • readonly stderr: Buffer
  • readonly stdout: Buffer
  • Read from stdout as an ArrayBuffer

    @returns

    Stdout as an ArrayBuffer

    const output = await $`echo hello`;
    console.log(output.arrayBuffer()); // ArrayBuffer { byteLength: 6 }
    
  • Read from stdout as a Blob

    @returns

    Stdout as a blob

    const output = await $`echo hello`;
    console.log(output.blob()); // Blob { size: 6, type: "" }
    
  • Read from stdout as an Uint8Array

    @returns

    Stdout as an Uint8Array

    const output = await $`echo hello`;
    console.log(output.bytes()); // Uint8Array { byteLength: 6 }
    
  • json(): any

    Read from stdout as a JSON object

    @returns

    Stdout as a JSON object

    const output = await $`echo '{"hello": 123}'`;
    console.log(output.json()); // { hello: 123 }
    
  • text(encoding?: BufferEncoding): string

    Read from stdout as a string

    @param encoding

    The encoding to use when decoding the output

    @returns

    Stdout as a string with the given encoding

    Read as UTF-8 string

    const output = await $`echo hello`;
    console.log(output.text()); // "hello\n"
    

    Read as base64 string

    const output = await $`echo ${atob("hello")}`;
    console.log(output.text("base64")); // "hello\n"