问题标签 [ocaml-lwt]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ocaml - 编译 ocaml-websocket 失败
尝试构建 ocaml-websocket,它失败了:
有问题的功能线是,
任何想法,如果 lwt API 在以前的版本中发生了变化?
ocaml - How to fully utilise `lwt` in this case
Here is what I am going to do:
I have a list of task
and I need to run them all every 1 hour (scheduling).
All those tasks are similar. for example, for one task, I need to download some data from a server (using http protocol and would take 5 - 8 seconds) and then do a computation on the data (would take 1 - 5 seconds).
I think I can use lwt
to achieve these, but can't figure out the best way for efficiency.
For the task scheduling part, I can do like this (How to schedule a task in OCaml?):
The questions come from the actual do_task part.
So a task involves http download
and computation
.
The http download
part would have to wait for 5 to 8 seconds. If I really execute each task one by one, then it wastes the bandwidth and of course, I wish the download process of all tasks to be in parallel. So should I put this download part to lwt? and will lwt handle all the downloads in parallel?
By code, should I do like this?:
So, through the code above, will all tasks be executed in parallel, at least for the http download
part?
For calculation part, will all calculations be executed in sequence?
Furthermore, can any one briefly describe the mechanism of lwt
? Internally, what is the logic of light weight thread
? Why can it handle IO in parallel?
ocaml - How to enable syntax color and indention for lwt in Emacs Tuareg mode?
I am using Tuareg mode for Emacs.
I am also using lwt
. lwt
has some syntax extension, but Tuareg cannot recognize them and it is ugly without indention and coloring.
I found this:
https://github.com/skydeck/lwt/blob/master/utils/tuareg-2.0.4.patch
It is a patch for tuareg-2.0.4 to enable lwt coloring.
However, I am using Tuareg-2.0.5 and I tried the patch directly, it failed.
I am not sure how to downgrade Tuareg, so I just downloaded the files of tuareg-2.0.4 and copy them to the elpa/tuareg-2.0.5
folder and then I did the patch again.
This was successfully patched as it said, but still my emacs cannot recognize lwt
.
Can anyone tell me how?
ocaml - 如何制作支持 lwt 的东西?
我试图理解这个词lwt supported
。
所以假设我有一段代码可以连接数据库并写入一些数据:Db.write conn data
. 它与 lwt 无关,每次写入都会花费10 sec
.
现在,我想使用 lwt。我可以像下面这样直接编码吗?
支持有5
数据项my_data_list
,5个数据项是顺序写入数据库还是并行写入数据库?
他们还说在 Lwt 中手动或http://ocsigen.org/tutorial/application
使用 Lwt 非常容易并且不会造成麻烦,前提是您从不使用阻塞函数(非协作函数)。阻塞函数会导致 entre 服务器挂起!
我完全不明白如何不使用阻塞功能。对于我自己的每一个功能,我可以用Lwt.return
它来制作它lwt support
吗?
mysql - Lwt 和数据库访问
我无法使用 lwt 进行数据库访问。我应该将它包含在一个线程中吗?如何?或者创建一个返回'a lwt
值的新线程?如果是这样,如何处理该值?
也是如此Printf.eprintf
,它似乎也被 lwt 阻止了。所以我改用 Lwt_io。但为什么 lwt 会阻止常规 io?
我所拥有的是一个简单的数据库请求,例如Db.update session
. 它在一个Lwt_main.run main
函数内。所有这些都在一个 CGI 脚本中(没关系,数据库访问工作正常,直到我开始使用 lwt 命令)。
如果需要,我可以给你更多代码。
问候
Olle
编辑
编辑 2
这是解决方案:
garbage-collection - How to stop OCaml garbage collecting my reactive event handler?
I'm trying to use the OBus library with Lwt_react. This uses "functional reactive programming" for properties and signals.
The problem (as noted in the React documentation) is that OCaml may garbage collect your callback while you're still using it. There's a keep
function, which keeps the handler forever, but I don't want that. I do want to free it eventually, just not while I still need it.
So, I thought I'd attach the handler to a switch:
But my event handler gets garbage-collected anyway (which makes sense, since the code to turn off the switch is called when the signal arrives, so it's only the signal handler keeping the switch alive in the first place).
Here's a simplified (stand-alone) version of my code:
Without the Gc.full_major
line, this normally prints Done
. With it, it just hangs at Waiting for signal...
.
Edit: I've split setup
(the real code) from the test driver and added a Lwt.protected
wrapper to avoid masking the problem by accident of Lwt's cancellations.
ocaml - 使用 Lwt_term 编译程序
我在 OCaml 中有以下代码:
当我尝试使用编译时
我收到以下错误:
我知道这与上面的问题无关,但是从 utop 我可以打开 Lwt 但我仍然无法打开 Lwt_term。我究竟做错了什么?
utf-8 - OCaml websocket“无效的UTF8数据”
我正在尝试使用 Lwt 构建一个循环,将帧推送到 Websocket,等待响应,将其打印到屏幕上,等待 60 秒,然后再次重复该过程。我已经能够得到可以编译的东西,但我还没有 100% 正确。第一次通过循环一切正常,然后每次我收到错误消息“无效的 UTF8 数据”。我的 Lwt 循环或我对 Websocket 协议的理解一定有问题。我的代码:
ocaml - 如何使用异步代码中的 Lwt 库?
我发现了这个:https ://github.com/janestreet/lwt-async
但我完全不明白它应该去哪里。它是 Lwt 的替代品,我只需要在编译时放入我的文件夹并链接吗?
是否有另一种方法可以从使用 Jane Street 的 Async 的代码库中调用 Lwt 代码?
谢谢。
ocaml - 一起使用 Core 和 Lwt
我在我正在研究的库中同时使用 Core 和 Lwt。Core 有我熟悉的好模块,而且我更喜欢 Lwt 线程。
这是常见的事情吗?是否有充分的理由不这样做,而是使用,比如说,只使用核心或只使用 Lwt + 电池?