internal MainLoop loop;

void read_file (string file_name) yields {
	File file;
	FileInputStream file_input_stream;

	print ("Going to read '%s'\n", file_name);

	file = File.new_for_commandline_arg (file_name);

	try {
		file_input_stream = file.read ();

		debug ("Got the GFileInputStream. Now sleeping 3000 msec from coroutine");
		sleep (Priority.DEFAULT, 3000);
		debug ("Done sleeping 3000 msec. Now reading data from stream.");

		try {
			char[] buf = new char[1024];
			ssize_t bytes_read = file_input_stream.read (buf);
			print ("Read %zi bytes: '%s'\n", bytes_read, (string) buf);
		} catch (IOError e2) {
			printerr ("Error reading from file input stream for %s: %s\n", file_name, e2.message);
		}
	} catch (IOError e1) {
		printerr ("Error getting file input stream for %s: %s\n", file_name, e1.message);
	}

	loop.quit ();
}

bool print_mark () {
	print ("in print_mark()\n");
	return true;
}

int main (string[] args) {
	if (args.length != 2) {
		printerr ("Usage: async <filename>\n");
		return 1;
	}

	loop = new MainLoop (null, false);
	read_file.begin (args[1]);

	Timeout.add (500, print_mark);
	loop.run ();

	return 0;
}

