dominicletz
Creator of Elixir Desktop
OnCrash - Method to attach a callback to a process exit
After having this done a couple of times in different projects I decided to make this quick helper method that creates a monitor, attaches it to the desired process and fires a fun when the process goes down.
So makes it easy as pie to attach a cleanup() function to a process:
spawn(fn ->
OnCrash.call(fn -> cleanup() end)
do_the_work()
end)
That’s really all there is to it. Ah and if you’re curious about the exit reason you can have that as well:
spawn(fn ->
OnCrash.call(fn reason -> cleanup(reason) end)
do_the_work()
end)
https://hexdocs.pm/oncrash/OnCrash.html
Make a comment if this is helpful for you as well!
Cheers!
Popular in Libraries
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure).
1.0-rc.1 is now available. To use it re...
New
I released Doggo, a collection of unstyled Phoenix components.
Features
Unstyled Phoenix components.
Storybook that can be added to...
New
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs.
Generate and serve a JSON Open API ...
New
Hi all!
I’m happy to announce that Telemetry v0.3.0 is out! This release marks the conversion from Elixir to Erlang so that all the libr...
New
Hello everyone,
I wrote a small library today called MapDiff.
It returns a map listing the (smallest amount of) changes to get from map...
New
EctoJob
A transactional job queue built with Ecto, PostgreSQL and GenStage
Available on Hex.pm: ecto_job | Hex
Docs: API Reference — ec...
New
Hi there,
for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
import Meeseeks.CSS
html = HTTPoison.get!("https://news.ycombinator.com/").body
for story <- Meeseeks.all(html, css("tr.athing")) do...
New
Hey everyone!
Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
Prometheus metrics and Grafana dashboards for all of your favorite Elixir libraries
I have been put...
New
Other popular topics
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New







