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
import 'package:flutter/material.dart'; | |
import 'dart:typed_data'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); |
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
class HypotheticalService { | |
final _stack = <Event>[]; | |
Event? _lastDisplayed; | |
void reportEvent(Event event) { | |
print("${DateTime.now()} Adding ${event.runtimeType} to stack"); | |
_stack.add(event); | |
_outputLatest(); | |
} |
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
# [debug] frame time: 495ms, listeners: 1, changes: 14 | |
[ | |
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 4, 1, 1, | |
0, 0, 147, 204, 255, 204, 255, 204, 255>>, | |
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 5, 1, 1, | |
0, 0, 147, 204, 255, 204, 255, 204, 255>>, | |
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 6, 1, 1, | |
0, 0, 147, 204, 255, 204, 255, 204, 255>>, | |
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 7, 1, 1, | |
0, 0, 147, 204, 255, 204, 255, 204, 255>>, |
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
use Bitwise | |
defmodule Telegram do | |
use Bitwise | |
@byte 8 | |
@bloc_size 4 * @byte | |
def get_bloc(telegram, bloc_nr) do | |
<<bloc::size(32)>> = binary_part(telegram, 2 + (bloc_nr - 1) * 4, 4) |
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
defmodule Pragmatic do | |
def supervisor(worker) do | |
spawn_link(fn -> | |
worker_pid = spawn_link(worker) | |
Process.register(worker_pid, :worker) # <- I added this so we can find our worker | |
Process.flag(:trap_exit, true) | |
receive do | |
{:EXIT, ^worker_pid, _} -> | |
supervisor(worker) | |
end |
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
defmodule Pragmatic do | |
def worker(state \\ nil) do | |
receive do | |
{:set, value} -> | |
worker(value) | |
{:get, from} -> | |
send(from, state) | |
worker(state) | |
end |
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
worker_function = fn -> | |
:timer.sleep(1_000) | |
IO.puts("completed at #{:erlang.system_time()}") | |
end | |
Pragmatic.supervisor(worker_function) | |
#> completed at 1556621845035672000 | |
#> completed at 1556621846038645599 | |
#> completed at 1556621847039733259 |
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
defmodule Pragmatic do | |
def supervisor(worker) do | |
spawn_link(fn -> | |
Process.flag(:trap_exit, true) | |
worker_pid = spawn_link(worker) | |
receive do | |
{:EXIT, ^worker_pid, _} -> | |
supervisor(worker) | |
end | |
end) |
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
defmodule Recursive do | |
def function do | |
receive do | |
_ -> function() | |
end | |
end | |
end |
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
defmodule Recursive do | |
def function do | |
function() | |
end | |
end |
NewerOlder