Javascript: Promisification

JS: Asynchronous programming
Last update: 19 Jan 23:20
0
Students

promisify.js

Implement and export as default a function that "promisifies" asynchronous functions with callbacks.

import promisify from '../promisify.js';

const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);

const filepath = '/tmp/myfile';

writeFile(filepath, 'content')
  .then(() => readFile(filepath))
  .then(console.log);

When implementing asynchronous functions, remember that the callback is always passed by the last parameter. ​

Tips

  • Use rest and spread operatores

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests