Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the type of promise #387

Closed
pouyakary opened this issue Dec 23, 2016 · 1 comment
Closed

Problem with the type of promise #387

pouyakary opened this issue Dec 23, 2016 · 1 comment

Comments

@pouyakary
Copy link

TS and JS Grammar Extension version: VSCode 1.9 Insiders, latest daily build

Problem
problem-with-promise-types

Code

//
// Copyright 2016 Kary Foundation, Inc.
//   Author: Pouya Kary <k@karyfoundation.org>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

//
// ─── IMPORTS ────────────────────────────────────────────────────────────────────
//

    import * as readline from 'readline';

//
// ─── READLINE ───────────────────────────────────────────────────────────────────
//

    /**
     * Reads a string from the command line
     * ```
     * async function main ( ) {
     *    let name = await kary.terminal.input('Your name: ')
     *    console.log(`Hello, ${ name }!`)
     * }
     * ```
     */
    export async function input ( message = '' ) {
        const readlineInterface = readline.createInterface({
            input: process.stdin,
            output: process.stdout,
        })
        return new Promise<string> ( resolve => {
            readlineInterface.question ( message , answer => {
                readlineInterface.close( );
                resolve( answer );
            });
        });
    }

// ────────────────────────────────────────────────────────────────────────────────
@pouyakary
Copy link
Author

thanks a lot 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant