-
-
Save russelldb/4f8fe205bd5a5a1cd136 to your computer and use it in GitHub Desktop.
Run `f:loop(20).` on pre-r17 erlang, and be fine, run it on r17+ and be sad.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module(f). | |
-compile([export_all]). | |
loop(0) -> | |
done; | |
loop(N) -> | |
io:format("N ~p~n", [N]), | |
Fname = "rdb.file", | |
Bin = crypto:rand_bytes(8), | |
Term = [{name, Bin}], | |
IOLIst = io_lib:format("~p.", [Term]), | |
ok = write_file(Fname, IOLIst), | |
{ok, [Term]} = file:consult(Fname), | |
loop(N-1). | |
write_file(FN, Data) -> | |
case file:open(FN, [write, raw]) of | |
{ok, FH} -> | |
try | |
ok = file:write(FH, Data), | |
ok = file:sync(FH), | |
ok = file:close(FH), | |
ok | |
catch _:Err -> | |
{error, Err} | |
end; | |
Err -> | |
Err | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment