namespace eval foo {
    namespace ensemble create -subcommands {initialize finalize watch write}
}

proc foo::initialize {id mode} {
    return [namespace ensemble configure foo -subcommands]
}

proc foo::watch {id spec} {
    if {"write" in $spec} {
       	chan postevent $id write
    }
}

proc contact {fd} {
    chan event $fd writable {}
}

set fd [chan create write foo]
chan event $fd writable [list contact $fd]
