about summary refs log tree commit diff stats
path: root/src/task.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-03-05 18:04:35 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-03-05 18:04:35 -0800
commit52ae23784b5474298c6ada6252f5a785fc5e8c19 (patch)
tree519e3b3812f4543161b5c4ed9674a7e2b59bb785 /src/task.lua
parent2d6b88204bca1787cbcc08bbff4383e1980cd196 (diff)
downloadteliva-52ae23784b5474298c6ada6252f5a785fc5e8c19.tar.gz
new API for file operations
File operations now always return a channel (or nil on error or
permission denied).

When start_reading() from a filename, you can repeatedly :recv() from
the channel it returns.
When :recv() returns nil, you're at the end of the file. Stop.

When you start_writing() to a filename, you can repeatedly :send() to
the channel it returns.
When you're done writing, :close() the channel. Writes to the file won't
be externally visible until you do.

To make this work I'm now always starting up the scheduler, so I need to
fix sieve.tlv.

Transparently running the scheduler is an abstraction, and whenever I
create an abstraction I always worry about how it might fail. There's
a hopefully-clear error when you read past end of a file.
Diffstat (limited to 'src/task.lua')
-rw-r--r--src/task.lua11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/task.lua b/src/task.lua
index 8d03316..3b00ef6 100644
--- a/src/task.lua
+++ b/src/task.lua
@@ -380,6 +380,17 @@ _M.RECV      = RECV
 _M.SEND      = SEND
 _M.NOP       = NOP
 
+-- Specific to Teliva
+function spawn_main()
+  task.spawn(main)
+  task.scheduler()
+  assert(false, "Teliva's scheduler ran out of work; this shouldn't happen.\n"..
+                "Either a channel is blocked forever or you're reading past\n"..
+                "the end of a file (after recv() returned nil).\n")
+  curses.nodelay(true)
+  curses.getch()
+end
+
 ----------------------------------------------------------------------------
 ----------------------------------------------------------------------------
 -- Tests