Interesting...
Here is the 8th version of the sample program used in
language comparison.
I got rid of the mutex guarded ids access inside the tasks and pass each task it's own slice of work. Fastest way to lock is not to lock. I also discovered a bug in 8th's current "tlshello" implementation. It currently won't play nice if used concurrently and it's access should be guarded with a lock. Bug report is filed!
needs net/http
var ids
[] var, tasks
\ Locker words. Locked variable is embedded into word, so wastes no dictionary space on captive locker variable.
"" dup
: lock-write literal lock drop ;
: unlock-write literal unlock drop ;
: STORIES_URL "https://hacker-news.firebaseio.com/v0/topstories.json" ;
: ITEM_URL_BASE "https://hacker-news.firebaseio.com/v0/item/" ;
: get-ids
STORIES_URL net:get if
nip json>
' >s a:map ids !
else
"Error retrieving data." throw
then ;
: task \ ids-slice --
( nip ITEM_URL_BASE "%s%s.json" s:strfmt net:get if
nip json>
"title" m:@ nip
lock-write . cr unlock-write
else
"Error retrieving data." throw
then
) a:each drop ;
: start-tasks
tasks @
( ids @ swap -1 8 a:slice+ 1 ' task t:task-n a:push ) 0 7 loop
drop ;
: wait-tasks
tasks @ t:wait ;
: app:main
get-ids
start-tasks
wait-tasks
bye ;