Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
eeue56-elm-ffi
Advanced tools
A FFI interface for Elm
:fire: :bangbang: This library is intended for experienced Elm developers only! If you haven't written a lot of Elm and end up here, try asking about your problem on Slack instead! :bangbang: :fire:
:fire: Both sync
and async
functions can introduce runtime errors in Elm and break everything. safeAsync
and safeSync
can be used more safely, as they wrap each call in try..catch
and return a result. Note, if safeAsync
's code fails during callback evaluation, it will not be returned as a result and will cause runtime errors. Because of this, this library should only really be used for prototyping ideas. This is not a production quality library. :fire:
You need elm-proper-install to install this package
elm-proper-install eeue56/elm-http-server
You'll also need to add "native-modules": true
to your elm-package.json
.
Imagine you want to define your own logging function, but don't want the wrapper from Debug.log
.
With this library, you can do the following:
import FFI
log : a -> ()
log thing =
FFI.sync "console.log(_0);" [ FFI.asIs thing ]
|> (\_ -> ())
which can then be used like this:
someFunction =
let
_ = log "Some thing is being called!"
in
5
Each argument is applied in order of the list of arguments given - so _0
is the first argument, then _1
is the second and so on.
In order to ensure that the code works okay, ensure that any function you make takes each argument seperately. Otherwise, the functions no longer work properly with partial application.
Note that safeSync
exists in order to allow for safer creation of runtime functions, by instead returning a Result
. For example:
safeLog : a -> ()
safeLog thing =
case FFI.safeSync "console.log(_0);" [ FFI.asIs thing ] of
Err message ->
let
_ = Debug.log "FFI log function did not work!"
in
()
Ok v ->
()
Imagine you want to return a value after a certain amount of time. You'd write
import FFI
returnAfterX : Int -> Value -> Task String Value
returnAfterX time value =
FFI.async """
setTimeout(function(){
callback(_succeed(_1))
}, _0)
"""
[ Json.Encode.int time, value ]
Now you can use this as you would any other task. _fail
can be used to produce the error task, while _succeed
is for success cases. You have to wrap this value in a call to callback
- which is used to tell the schedular that the task has completed.
FAQs
Elm FFI package
The npm package eeue56-elm-ffi receives a total of 0 weekly downloads. As such, eeue56-elm-ffi popularity was classified as not popular.
We found that eeue56-elm-ffi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.