util#promisify JavaScript Examples

The following examples show how to use util#promisify. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: gdrive.js    From HinataMd with GNU General Public License v3.0 6 votes vote down vote up
async authorize(credentials) {
    let token
    const { client_secret, client_id } = credentials
    const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, `http://localhost:${port}`)
    try {
      token = JSON.parse(await fs.readFile(TOKEN_PATH))
    } catch (e) {
      const authUrl = oAuth2Client.generateAuthUrl({
        access_type: 'offline',
        scope: SCOPES
      })
      this.emit('auth', authUrl)
      let code = await promisify(this.once).bind(this)('token')
      token = await oAuth2Client.getToken(code)
      await fs.writeFile(TOKEN_PATH, JSON.stringify(token))
    } finally {
      await oAuth2Client.setCredentials(token)
    }
  }
Example #2
Source File: index.js    From clipcc-desktop with GNU Affero General Public License v3.0 6 votes vote down vote up
initialProjectDataPromise = (async () => {
    if (argv._.length === 0) {
        // no command line argument means no initial project data
        return;
    }
    if (argv._.length > 1) {
        log.warn(`Expected 1 command line argument but received ${argv._.length}.`);
    }
    const projectPath = argv._[argv._.length - 1];
    try {
        const projectData = await promisify(fs.readFile)(projectPath, null);
        return projectData;
    } catch (e) {
        dialog.showMessageBox(_windows.main, {
            type: 'error',
            title: 'Failed to load project',
            message: `Could not load project from file:\n${projectPath}`,
            detail: e.message
        });
    }
    // load failed: initial project data undefined
})()
Example #3
Source File: promisifiedCall.js    From juggernaut-desktop with MIT License 6 votes vote down vote up
/**
 * promisifiedCall - Promisifies specified method and calls it with @thisArg as this and passes @args as an object.
 *
 * @param {*} thisArg This arg
 * @param {*} method Method to promisy
 * @param {*} args Arguments to pass call method with
 * @returns {Function} Promisified method
 */
export default function promisifiedCall(thisArg, method, ...args) {
  return promisify(method).call(thisArg, ...args);
}
Example #4
Source File: fs-utils.js    From Nextjs-ja-translation-docs with MIT License 6 votes vote down vote up
readFile = promisify(fs.readFile)
Example #5
Source File: redis.service.js    From Docker-for-Developers with MIT License 6 votes vote down vote up
init() {
    const redis_host = process.env.REDIS_HOST ?? 'localhost';
    const redis_port = process.env.REDIS_PORT ?? 6379;
    const redis_password = process.env.REDIS_PASSWORD ?? '';
    const redis_options = {};
    l.info({
      msg: 'Connecting to Redis',
      redis_host: redis_host,
      redis_port: redis_port,
      redis_password: redis_password.replace(/./g, 'X'),
    });
    const redis_url = `redis://${redis_host}:${redis_port}`;
    let client = redis.createClient(redis_url, redis_options);
    l.debug({
      msg: 'Redis configured',
      redis_url: redis_url,
    });
    // Thanks https://stackoverflow.com/a/18560304
    client.on('error', err => l.error({ msg: 'Redis error', err: err }));
    if (redis_password !== '') {
      client.auth(redis_password);
      l.info({
        msg: 'Redis authenticated OK',
        redis_url: redis_url,
      });
    }
    client.pingAsync = promisify(client.ping).bind(client);
    client.getAsync = promisify(client.get).bind(client);
    client.setAsync = promisify(client.set).bind(client);
    client.incrbyAsync = promisify(client.incrby).bind(client);
    return client;
  }
Example #6
Source File: buildI18n.js    From emoji-picker-element with Apache License 2.0 6 votes vote down vote up
async function main () {
  const targetDir = path.join(__dirname, '../i18n')

  await promisify(rimraf)(targetDir)
  await mkdirp(targetDir)

  const sourceDir = path.join(__dirname, '../src/picker/i18n')

  const sourceFiles = await readdir(sourceDir)

  await Promise.all(sourceFiles.map(async sourceFile => {
    await Promise.all([
      copyFile(path.join(sourceDir, sourceFile), path.join(targetDir, sourceFile)),
      writeFile(path.join(targetDir, sourceFile.replace('.js', '.d.ts')), `
import { I18n } from "../shared";
declare const _default: I18n;
export default _default;
      `.trim())
    ])
  }))
}
Example #7
Source File: stats.js    From gidget with Apache License 2.0 5 votes vote down vote up
usagePercent = promisify(cpuStat.usagePercent)
Example #8
Source File: upload.js    From zora.gallery with MIT License 5 votes vote down vote up
readFileAsync = promisify(fs.readFile)
Example #9
Source File: ini-server.js    From HinataMd with GNU General Public License v3.0 5 votes vote down vote up
exec = promisify(cp.exec).bind(cp)
Example #10
Source File: message.js    From Spoke with MIT License 5 votes vote down vote up
redisSet = promisify(r.redis.set).bind(r.redis)
Example #11
Source File: library-files.js    From desktop with GNU General Public License v3.0 5 votes vote down vote up
readFile = promisify(fs.readFile)
Example #12
Source File: adapter.js    From packager with Apache License 2.0 5 votes vote down vote up
readFile = promisify(fs.readFile)
Example #13
Source File: index.js    From cs-wiki with GNU General Public License v3.0 5 votes vote down vote up
access = promisify(fs.access)
Example #14
Source File: early-exit.js    From action-dependabot-auto-merge with MIT License 5 votes vote down vote up
pexec = promisify(exec)
Example #15
Source File: index.es.js    From smart-contracts with MIT License 5 votes vote down vote up
exists = promisify(fs.exists)
Example #16
Source File: index.js    From v8-deopt-viewer with MIT License 5 votes vote down vote up
execFileAsync = promisify(execFile)
Example #17
Source File: path.js    From aresrpg with MIT License 5 votes vote down vote up
setTimeoutPromise = promisify(setTimeout)
Example #18
Source File: programmatic.js    From eslint-formatter-badger with MIT License 5 votes vote down vote up
readFile = promisify(rf)
Example #19
Source File: redis.js    From Edlib with GNU General Public License v3.0 5 votes vote down vote up
RedisService = {
    getAsync: promisify(client.get).bind(client),
    setAsync: promisify(client.set).bind(client),
}
Example #20
Source File: sleep.js    From ftx-cli with MIT License 5 votes vote down vote up
setTimeoutPromise = promisify(setTimeout)
Example #21
Source File: index.js    From playwright-test with MIT License 5 votes vote down vote up
writeFile = promisify(fs.writeFile)
Example #22
Source File: index.js    From watchlist with MIT License 5 votes vote down vote up
toExec = promisify(exec)
Example #23
Source File: index.js    From millix-node with MIT License 5 votes vote down vote up
constructor() {
        super('DjwvDZ4bGUzKxOHW');
        dns.setServers(config.NODE_DNS_SERVER);
        this.resolveTxt = promisify(dns.resolveTxt);
    }
Example #24
Source File: file_mgr.js    From freyr-js with Apache License 2.0 5 votes vote down vote up
open = promisify(fs.open)
Example #25
Source File: common.js    From Pixiv_bot with MIT License 5 votes vote down vote up
exec = { promisify }.promisify(({ exec: exec$0 }).exec)
Example #26
Source File: async-folder.js    From nanoexpress with Apache License 2.0 5 votes vote down vote up
fsReadDir = promisify(readdir)
Example #27
Source File: fs.js    From emoji-picker-element with Apache License 2.0 5 votes vote down vote up
readFile = promisify(fs.readFile)
Example #28
Source File: index.js    From FinDevs with MIT License 5 votes vote down vote up
// import logo from '../../assets/Logo3.png';

function Main({ history }) {
  const [devs, setDevs] = useState([]);
  const [loggedDev, setLoggedDev] = useState('');


  useEffect(() => {
    async function loadLoggedDev() {
      const token = await localStorage.getItem('findevs-token');

      const decoded = await promisify(jwt.verify)(token, authConfig.secret);

      const { github_user } = decoded;

      const response = await api.get(`dev/${github_user}`);

      setLoggedDev(response.data);
    }

    loadLoggedDev();
  }, []);

  // load devs
  useEffect(() => {
    async function loadDevs() {
      const response = await api.get('/devs');

      setDevs(response.data);
    }
    // decode token to get logged user


    loadDevs();
  }, []);


  // inative user - disable
  function hadleHide() {
    alert('This feat is under construction for now!');
  }

  // logout func
  function logout() {
    localStorage.removeItem('findevs-token');
    history.push('/');
  }


  return (
    <div id="main">
      <aside>
        <DevProfile dev={loggedDev} key={loggedDev.name} logout={logout} handleHide={hadleHide} />
      </aside>
      <main>
        <ul>
          {devs.map((dev) => (
            <DevItem dev={dev} key={dev._id} />
          ))}
        </ul>
      </main>
    </div>
  );
}
Example #29
Source File: challs.js    From rctf with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
redisSubscribe = promisify(subClient.subscribe.bind(subClient))