Commit ae549652 authored by Avi's avatar Avi

Current place in wip with promisify

parent fdcc9b4a
Pipeline #16429 failed with stages
in 10 minutes and 22 seconds
......@@ -9,9 +9,15 @@ const {promisify} = imports.promisify;
const cancel = new Gio.Cancellable();
let loop = GLib.MainLoop.new(null, false);
/* This is a workaround for now */
// const Gio_File_prototype = Gio.File.new_for_path('').constructor.prototype;
const Gio_File_prototype = Gio.File.new_for_path('').constructor.prototype;
// let load_contents_async;
Gio_File_prototype.load_contents_promise = promisify(Gio_File_prototype, 'load_contents_async','load_contents_finish');
/*
This line:
Gio_File_prototype.load_contents_promise = promisify(Gio_File_prototype, 'load_contents_async', 'load_contents_finish');
Is supposed to be the equivalent to this:
*/
// Gio_File_prototype.load_contents_promise = function(...args){
// return new Promise((resolve, reject)=>{
// this.load_contents_async(...args, function(f, res) {
......@@ -43,10 +49,11 @@ const head = async(filename)=>{
let file = Gio.file_new_for_commandline_arg(filename);
let content_formatted;
try {
let load_contents = promisify.load_contents_async(Gio_File_prototype,load_contents_async,load_contents_finish);
print (`This should be load_contents: ${load_contents}`);
// let load_contents = promisify.load_contents_async(Gio_File_prototype,load_contents_async,load_contents_finish);
// print (`This should be load_contents: ${load_contents}`);
// let
/* To cancel the operation toggle the 'null' with the 'cancel' param */
let [, raw_content] = await file.load_contents(/*nullcancel*/);
let [, raw_content] = await file.load_contents_promise(null/*cancel*/);
content_formatted = raw_content.toString();
print(content_formatted.split('\n', 10).join('\n'));
} catch (error) {
......@@ -56,6 +63,22 @@ const head = async(filename)=>{
}
};
/* Original */
// const head = async(filename)=>{
// let file = Gio.file_new_for_commandline_arg(filename);
// let content_formatted;
// try {
// /* To cancel the operation toggle the 'null' with the 'cancel' param */
// let [, raw_content] = await file.load_contents_promise(null/*cancel*/);
// content_formatted = raw_content.toString();
// print(content_formatted.split('\n', 10).join('\n'));
// } catch (error) {
// logError(error);
// } finally {
// loop.quit();
// }
// };
if (ARGV.length !== 1) {
printerr('Usage: gio-head.js filename');
} else {
......
const {GLib, Gio} = imports.gi;
// const {GLib, Gio} = imports.gi;
// const promisify = ({
// selectFunc,
......@@ -23,7 +23,7 @@ var promisify = ( /* Apparently const isn't supported thus using var */
finishStuff /* load_contents_finish */
) => {
// Gio_File_prototype.load_contents_promise = function(...args){
return GioType[asyncStuff] = function(...args){
// GioType[asyncStuff] = function(...args){
return new Promise((resolve, reject)=>{
/* this[asyncStuff] == this.load_contents_async */
// this.load_contents_async(...args, function(source,res){
......@@ -39,7 +39,7 @@ var promisify = ( /* Apparently const isn't supported thus using var */
});
});
}
}
// }
/* Original (This one works) */
// Gio_File_prototype.load_contents_promise = function(...args){
......
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