pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
wilkerlucio 2021-01-20T05:13:45.017800Z

4❤️
thheller 2021-01-20T10:42:10.018Z

hey, did you consider using a protocol for the async support so its not coupled to promesa or core.async or whatever and instead is extensible?

thheller 2021-01-20T10:46:53.018300Z

something like

(defprotocol IAsyncResult
  (on-result [this success-fn error-fn]))

;; conditional dispatch to async if needed
(if (satisfies? IAsyncResult result)
  (on-result result handle-success handle-error)
  (process-sequentially-somehow result))

;; in a js-promise ns
(extend-protocol IAsyncResult
  js/Promise
  (on-result [this success error]
    (-> this
        (.then success)
        (.catch error))))

;; in a promesa ns
;; same thing, only importing this ns is optional, API doesn't change

thheller 2021-01-20T10:47:13.018500Z

same for core.async and so on

wilkerlucio 2021-01-20T14:05:29.020500Z

Promesa has such protocols, so you can use them to extend other kinds of futures to conform to it, I did an example on how to make core-async compliant on the docs

wilkerlucio 2021-01-20T14:06:06.021600Z

do you have any concerns to extending from the promesa side?

thheller 2021-01-20T14:17:24.021800Z

I don't like adding promesa as a dependency in my projects when I don't have to

wilkerlucio 2021-01-20T14:20:42.022100Z

I would have to add something, because of the primitives to run in pathom, I dont want to write a portable future impl between clj and cljs, that's why Promesa (which goes quite close to the core of ComputableFuture on the JVM and Promises on JS)

wilkerlucio 2021-01-20T14:21:34.022300Z

in contrast, no more dep on core.async

thheller 2021-01-20T14:24:38.022600Z

yeah its probably fine. has been a while since I used promesa and it likely corrected some of the stuff they did in the past

thheller 2021-01-20T14:25:22.022800Z

just think its a generally good idea to not couple yourself to one specific async impl

wilkerlucio 2021-01-20T14:26:30.023Z

yeah, I would totally prefer that, but the differences between environments are big enough that I think its worth in this case (also because Promesa is small, so in this case seems to do just what I need to it)

wilkerlucio 2021-01-20T14:27:13.023200Z

also already offers the protocols for extensions, so if you want to use core.async, manifold or anything else on your resolvers/mutations, there is the extension point already

wilkerlucio 2021-01-20T14:28:47.023400Z

what kind of issues you had with promesa in the past?

thheller 2021-01-20T14:32:26.023600Z

it used to ship its own promise impl but appears to just use js/Promise now so thats good

thheller 2021-01-20T14:32:39.023800Z

guess my main problem with it is gone then

1👍
mpenet 2021-01-20T16:15:52.026400Z

for core.async there's a cheaper way than what you do in the example: you can just make completablefuture extend the writePort/readPort protocol I think, so core.async can take/put a cf directly, that saves creating a channel.

mpenet 2021-01-20T16:16:12.026600Z

I might just send a PR for this, I am juggling with too much stuff right now

mpenet 2021-01-20T16:19:11.026900Z

something like that https://gist.github.com/hiredman/1788aa052f26d127c00a1679656026f0 (not sure the impl on the gist is correct tho)

wilkerlucio 2021-01-21T00:51:08.000300Z

but by looking at your code I guess its doing the reverse of what I'm doing

wilkerlucio 2021-01-21T00:51:31.000400Z

in my case I'm making core.async channels compatible with promises, so I can use promesa and read from channels as-if they were promises

wilkerlucio 2021-01-21T00:52:01.000500Z

while your example would allow a CompletionStage to be read as a channel

thheller 2021-01-20T10:42:10.018Z

hey, did you consider using a protocol for the async support so its not coupled to promesa or core.async or whatever and instead is extensible?

thheller 2021-01-20T10:46:53.018300Z

something like

(defprotocol IAsyncResult
  (on-result [this success-fn error-fn]))

;; conditional dispatch to async if needed
(if (satisfies? IAsyncResult result)
  (on-result result handle-success handle-error)
  (process-sequentially-somehow result))

;; in a js-promise ns
(extend-protocol IAsyncResult
  js/Promise
  (on-result [this success error]
    (-> this
        (.then success)
        (.catch error))))

;; in a promesa ns
;; same thing, only importing this ns is optional, API doesn't change

thheller 2021-01-20T10:47:13.018500Z

same for core.async and so on

wilkerlucio 2021-01-20T14:05:29.020500Z

Promesa has such protocols, so you can use them to extend other kinds of futures to conform to it, I did an example on how to make core-async compliant on the docs

wilkerlucio 2021-01-20T14:06:06.021600Z

do you have any concerns to extending from the promesa side?

thheller 2021-01-20T14:17:24.021800Z

I don't like adding promesa as a dependency in my projects when I don't have to

wilkerlucio 2021-01-20T14:20:42.022100Z

I would have to add something, because of the primitives to run in pathom, I dont want to write a portable future impl between clj and cljs, that's why Promesa (which goes quite close to the core of ComputableFuture on the JVM and Promises on JS)

wilkerlucio 2021-01-20T14:21:34.022300Z

in contrast, no more dep on core.async

thheller 2021-01-20T14:24:38.022600Z

yeah its probably fine. has been a while since I used promesa and it likely corrected some of the stuff they did in the past

thheller 2021-01-20T14:25:22.022800Z

just think its a generally good idea to not couple yourself to one specific async impl

wilkerlucio 2021-01-20T14:26:30.023Z

yeah, I would totally prefer that, but the differences between environments are big enough that I think its worth in this case (also because Promesa is small, so in this case seems to do just what I need to it)

wilkerlucio 2021-01-20T14:27:13.023200Z

also already offers the protocols for extensions, so if you want to use core.async, manifold or anything else on your resolvers/mutations, there is the extension point already

wilkerlucio 2021-01-20T14:28:47.023400Z

what kind of issues you had with promesa in the past?

thheller 2021-01-20T14:32:26.023600Z

it used to ship its own promise impl but appears to just use js/Promise now so thats good

thheller 2021-01-20T14:32:39.023800Z

guess my main problem with it is gone then

1👍
2021-01-20T15:57:09.025500Z

Hey all, is there a recommended way to compose transforms? It looks like currently only one function is accepted so my first though is to just reach for comp

wilkerlucio 2021-01-20T16:08:05.025600Z

I was thinking about that yesterday

wilkerlucio 2021-01-20T16:08:35.025800Z

the idea I have is to make transport supports vectors, in the same way register does

wilkerlucio 2021-01-20T16:09:08.026Z

so you could do as: ::pco/transform [t1 t2 t3]

wilkerlucio 2021-01-20T16:10:04.026200Z

but before that you can use comp, single param in and out, works fine

mpenet 2021-01-20T16:15:52.026400Z

for core.async there's a cheaper way than what you do in the example: you can just make completablefuture extend the writePort/readPort protocol I think, so core.async can take/put a cf directly, that saves creating a channel.

mpenet 2021-01-20T16:16:12.026600Z

I might just send a PR for this, I am juggling with too much stuff right now

mpenet 2021-01-20T16:19:11.026900Z

something like that https://gist.github.com/hiredman/1788aa052f26d127c00a1679656026f0 (not sure the impl on the gist is correct tho)