[RxJS] Convert a Node.js style callback to Observable: bindNodeCallback

It's just like bindCallback, but the callback is expected to be of type callback(error, result).

import * as fs from 'fs';
const readFileAsObservable = bindNodeCallback(fs.readFile);
const result = readFileAsObservable('./roadNames.txt', 'utf8');
result.subscribe(x => console.log(x), e => console.error(e));

 

posted @ 2019-09-20 15:20  Zhentiw  阅读(279)  评论(0编辑  收藏  举报