Commit 249cadcd authored by Avi's avatar Avi

Swapped file and cancellable in load_contents_promise to clean up function

parent 8527b713
Pipeline #15165 failed with stages
in 5 minutes and 10 seconds
......@@ -3,24 +3,12 @@ const cancel = new Gio.Cancellable();
let loop = GLib.MainLoop.new(null, false);
const load_contents_promise = (cancellable = null, file)=>{
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);
let content_formatted;
try {
let [, raw_content] = await load_contents_promise(null, file);
/* To cancel the operation add the 'cancel' param at the end */
let [, raw_content] = await load_contents_promise(file /*, cancel*/);
content_formatted = raw_content.toString();
print(content_formatted.split('\n', 10).join('\n'));
} catch (error) {
......
......@@ -14,7 +14,7 @@
error GError a GError, or `NULL`
);
*/
const load_contents_promise = (cancellable = null, file)=>{
const load_contents_promise = (file, cancellable = null)=>{
return new Promise((resolve, reject)=>{
file.load_contents_async(cancellable, function(f, res) {
try {
......
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