Skip to content

Commit

Permalink
Support read_file only on non-browser environments (#496)
Browse files Browse the repository at this point in the history
* add missing fs import

* read_file doesn't work under browser

* different appraoch towards read_file

* remove dangling line
  • Loading branch information
om26er authored Feb 27, 2020
1 parent f9812c6 commit c5835c9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/autobahn/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ let sleep = async function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
};

let read_file = async function read_file (path) {
let _read_file = async function read_file (path) {
let fs = require("fs");
return new Promise((resolve, reject) => {
fs.readFile(path, function (err, data) {
if (err) {
Expand All @@ -429,6 +430,12 @@ let read_file = async function read_file (path) {
});
};

if ('fs' in global) {
exports.read_file = _read_file;
} else {
exports.read_file = null;
}


exports.handle_error = handle_error;
exports.rand_normal = rand_normal;
Expand All @@ -441,4 +448,3 @@ exports.new_global_id = new_global_id;
exports.deferred_factory = deferred_factory;
exports.promise = promise;
exports.sleep = sleep;
exports.read_file = read_file;

0 comments on commit c5835c9

Please sign in to comment.