Commit bb13756f authored by Avi's avatar Avi

First attempt of load_contents_promise being a method to file working

parent 249cadcd
......@@ -3,12 +3,28 @@ const cancel = new Gio.Cancellable();
let loop = GLib.MainLoop.new(null, false);
const load_contents_promise = (file, cancellable = null)=>{
return new Promise((resolve, reject)=>{
file.load_contents_async(cancellable, function(f, res) {
try {
let result = f.load_contents_finish(res);
resolve(result);
} catch (error) {
reject(error);
}
});
});
};
const head = async(filename)=>{
let file = Gio.file_new_for_commandline_arg(filename);
file.load_contents_promise = function(){
return load_contents_promise(file);
}
let content_formatted;
try {
/* To cancel the operation add the 'cancel' param at the end */
let [, raw_content] = await load_contents_promise(file /*, cancel*/);
let [, raw_content] = await file.load_contents_promise(/*, cancel*/);
content_formatted = raw_content.toString();
print(content_formatted.split('\n', 10).join('\n'));
} catch (error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment