Skip to content

Thread-safe version of with-spy and with-stub #45

Closed
@mourjo

Description

@mourjo

Bond uses with-redefs which binds the function's var's root to the new definition, which means it is visible to all threads that are currently executing, not necessarily the one in the context of with-spy or with-stub, for example

(defn funk [& args] args)

(future
  (bond/with-stub! [[funk (constantly -1)]]
    (Thread/sleep 10000)
    (funk)))

(funk 9) ;; => -1 (redefined function being called outside of with-stub)

;; after ten seconds
(funk 9) ;; => (9)

I was curious if you think using thread-local redefinitions is something you think would be useful here. For example, using https://gist.github.com/gfredericks/7143494

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions